(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 8.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[    114517,       2742]
NotebookOptionsPosition[    111389,       2631]
NotebookOutlinePosition[    111801,       2648]
CellTagsIndexPosition[    111758,       2645]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{

Cell[CellGroupData[{
Cell["Main file for SVM", "Title",
 CellChangeTimes->{{3.511340188359375*^9, 3.511340210625*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"BeginPackage", "[", "\"\<W`SVM`\>\"", "]"}], ";"}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340278125*^9}}],

Cell[CellGroupData[{

Cell["public interface", "Section",
 CellChangeTimes->{{3.512028715921875*^9, 3.5120287309375*^9}}],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"SVMTrain", "::", "usage"}], "=", 
   "\"\<SVMTrain[X, Y, options] use to train a SVM,\nX must be a \
matrix(sample must be 2d at least),Y is the label.\>\""}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"SVMClassify", "::", "usage"}], "=", 
    "\"\<use this function to classify\>\""}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"SVMSave", "::", "usage"}], "=", 
   "\"\<SVMSave[s,fn_:Null] save a svm to file\>\""}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"SVMLoad", "::", "usage"}], "=", 
    "\"\<SVMLoad[fn_:Null] load a saved svm from file\>\""}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"SVMPlot", "::", "usage"}], "=", "\"\<\>\""}], ";"}]}], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.511599676703125*^9}, {3.51166692153125*^9, 3.511666922125*^9}, {
   3.511668261703125*^9, 3.511668285953125*^9}, {3.511668730203125*^9, 
   3.511668732328125*^9}, {3.511675464734375*^9, 3.5116754671875*^9}, {
   3.511682987953125*^9, 3.51168300421875*^9}, {3.51168700184375*^9, 
   3.51168703459375*^9}, {3.5116937511875*^9, 3.511693752109375*^9}, {
   3.511694209046875*^9, 3.51169422590625*^9}, {3.511694543015625*^9, 
   3.5116945625625*^9}, {3.511695518296875*^9, 3.511695577984375*^9}, {
   3.51169690115625*^9, 3.511696907046875*^9}, {3.511740142921875*^9, 
   3.511740270734375*^9}, {3.511759235921875*^9, 3.51175923778125*^9}, {
   3.51175926809375*^9, 3.5117592928125*^9}, 3.511774208671875*^9, {
   3.51177424665625*^9, 3.511774248828125*^9}, {3.5117749868125*^9, 
   3.511775000171875*^9}, {3.5117752366875*^9, 3.511775272484375*^9}, {
   3.51177707015625*^9, 3.51177708528125*^9}, {3.511777233953125*^9, 
   3.511777239640625*^9}, 3.51178050109375*^9, {3.51178153803125*^9, 
   3.5117815508125*^9}, 3.511781668703125*^9, {3.5118595223125*^9, 
   3.511859609453125*^9}, {3.511910570859375*^9, 3.51191058328125*^9}, {
   3.5119116205625*^9, 3.511911626875*^9}, {3.512029475296875*^9, 
   3.512029479171875*^9}}],

Cell[CellGroupData[{

Cell["\<\
these routines are for debug purpose\
\>", "Subsection",
 CellChangeTimes->{{3.51202948159375*^9, 3.5120295440625*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", "*)"}], "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"KernelMatrix", "::", "usage"}], "=", 
     "\"\<KernelMatrix[K,X] computes the (full) matrix with elements K[x\
\[LeftDoubleBracket]i\[RightDoubleBracket],x\[LeftDoubleBracket]j\
\[RightDoubleBracket]].\>\""}], ";"}], "\[IndentingNewLine]", 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"IdentityKernel", "::", "usage"}], "=", 
     "\"\<IdentityKernel[x,y] is the function x.y.\>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"RBFKernel", "::", "usage"}], "=", 
     "\"\<RBFKernel[x,y,\[Gamma]] is the function \
Exp[-\[Gamma](x-y).(x-y)].\>\""}], ";"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"PolynomialKernel", "::", "usage"}], "=", 
     "\"\<PolynomialKernel[x,y,\[Gamma],d,c], where d is an integer, is the \
function (\[Gamma] x.y+c\!\(\*SuperscriptBox[\()\), \(d\)]\).\>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"QPSolve", "::", "usage"}], "=", 
     "\"\<QPSolve[X_,Y_,K_,Cs_,\[Tau]_,method_] is a wrapper func for QP \
problem, refer to qpType for method options\>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{
      RowBox[{"QPsolves", "::", "usage"}], "=", 
      "\"\<classic qpsolve, very slow\>\""}], ";"}], "*)"}], 
   "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{
      RowBox[{"oSVM", "::", "usage"}], "=", "\"\<test\>\""}], ";"}], 
    "*)"}]}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.511599676703125*^9}, {3.51166692153125*^9, 3.511666922125*^9}, {
   3.511668261703125*^9, 3.511668285953125*^9}, {3.511668730203125*^9, 
   3.511668732328125*^9}, {3.511675464734375*^9, 3.5116754671875*^9}, {
   3.511682987953125*^9, 3.51168300421875*^9}, {3.51168700184375*^9, 
   3.51168703459375*^9}, {3.5116937511875*^9, 3.511693752109375*^9}, {
   3.511694209046875*^9, 3.51169422590625*^9}, {3.511694543015625*^9, 
   3.5116945625625*^9}, {3.511695518296875*^9, 3.511695577984375*^9}, {
   3.51169690115625*^9, 3.511696907046875*^9}, {3.511740142921875*^9, 
   3.511740270734375*^9}, {3.511759235921875*^9, 3.51175923778125*^9}, {
   3.51175926809375*^9, 3.5117592928125*^9}, 3.511774208671875*^9, {
   3.51177424665625*^9, 3.511774248828125*^9}, {3.5117749868125*^9, 
   3.511775000171875*^9}, {3.5117752366875*^9, 3.511775272484375*^9}, {
   3.51177707015625*^9, 3.51177708528125*^9}, {3.511777233953125*^9, 
   3.511777239640625*^9}, 3.51178050109375*^9, {3.51178153803125*^9, 
   3.5117815508125*^9}, 3.511781668703125*^9, {3.5118595223125*^9, 
   3.511859609453125*^9}, {3.511910570859375*^9, 3.51191058328125*^9}, {
   3.5119116205625*^9, 3.511911626875*^9}, {3.512029475296875*^9, 
   3.512029479171875*^9}, {3.512031378265625*^9, 3.51203139434375*^9}}]
}, Closed]],

Cell[CellGroupData[{

Cell[" options", "Subsection",
 CellChangeTimes->{{3.512029516421875*^9, 3.51202952553125*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{"options", ":", " ", 
    RowBox[{"type", " ", "of", " ", "Kernel", " ", "and", " ", "SVM"}]}], 
   "*)"}], "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"svmType", "::", "usage"}], "=", 
     "\"\< =1, separable svm; =2, C-svm; =3, \[Nu]-SVM\>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"kernelType", "::", "usage"}], "=", 
     "\"\<=1, linear; =2, PolynomialKernel; =3, RBF; \>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"qpType", "::", "usage"}], "=", 
     "\"\<=1, old slow for C-svm; =2, Dlib SMO for C-svm; =3, Dlib for nu-Svm\
\>\""}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"cost", "::", "usage"}], "=", 
     "\"\<the parameter C(Cp and Cn for 2-class) of C-SVC,def: {1,1}\>\""}], 
    ";"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"nu", "::", "usage"}], "=", 
     "\"\<the parameter nu of nu-SVC\>\""}], ";"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"t", "::", "usage"}], "=", 
     "\"\<solution tolerance parameter, def: 0.001\>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"kernel", " ", "function", " ", "opt"}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"degree", "::", "usage"}], "=", "\"\<def: 3\>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"\[Gamma]", "::", "usage"}], "=", 
     "\"\<gamma in kernel, def: 1/num_feature\>\""}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"coef0", "::", "usage"}], "=", "\"\<def:0\>\""}], 
    ";"}]}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.511599676703125*^9}, {3.51166692153125*^9, 3.511666922125*^9}, {
   3.511668261703125*^9, 3.511668285953125*^9}, {3.511668730203125*^9, 
   3.511668732328125*^9}, {3.511675464734375*^9, 3.5116754671875*^9}, {
   3.511682987953125*^9, 3.51168300421875*^9}, {3.51168700184375*^9, 
   3.51168703459375*^9}, {3.5116937511875*^9, 3.511693752109375*^9}, {
   3.511694209046875*^9, 3.51169422590625*^9}, {3.511694543015625*^9, 
   3.5116945625625*^9}, {3.511695518296875*^9, 3.511695577984375*^9}, {
   3.511695739640625*^9, 3.51169577771875*^9}, {3.511738262375*^9, 
   3.511738263078125*^9}, {3.511758757828125*^9, 3.51175879121875*^9}, 
   3.511758920921875*^9, {3.511759137625*^9, 3.511759157125*^9}, {
   3.511759189765625*^9, 3.511759209984375*^9}, {3.511759312625*^9, 
   3.511759355*^9}, {3.511759526265625*^9, 3.5117595561875*^9}, {
   3.51175960209375*^9, 3.51175960303125*^9}, {3.511760448484375*^9, 
   3.511760458765625*^9}, {3.511770988125*^9, 3.511770999953125*^9}, {
   3.51177120803125*^9, 3.51177126578125*^9}, {3.511771320921875*^9, 
   3.511771383046875*^9}, {3.511771653625*^9, 3.51177165590625*^9}, {
   3.51177176896875*^9, 3.511771780015625*^9}, {3.51177193303125*^9, 
   3.511772005375*^9}, {3.51177531684375*^9, 3.511775420171875*^9}, {
   3.511777269640625*^9, 3.511777276875*^9}, {3.51177874584375*^9, 
   3.511778803328125*^9}, {3.511784526203125*^9, 3.51178455621875*^9}, {
   3.511826439921875*^9, 3.51182645859375*^9}, {3.511826586078125*^9, 
   3.511826592515625*^9}, {3.512015437609375*^9, 3.512015450671875*^9}, {
   3.51210341421875*^9, 3.51210341853125*^9}, {3.512188080875*^9, 
   3.512188135953125*^9}, {3.512192274703125*^9, 3.512192297765625*^9}, {
   3.512294459109375*^9, 3.512294495078125*^9}, {3.512295078765625*^9, 
   3.51229508234375*^9}, {3.512295145625*^9, 3.512295185375*^9}, {
   3.512355980828125*^9, 3.512356003234375*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
   "**", "**", "**", "**", "**", "**", "**", "**", "**", "**", "**", "**", "**",
     "**", "**", "**", "**", "**", "**", "**", "**", "**", "**", "**", "**", "**",
     "**", "**", "**", "**", "**"}], "******)"}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{"we", " ", "need", " ", "a", " ", "structure", " ", "to", " ", 
    StyleBox["save",
     FontColor->RGBColor[0.5, 0, 0.5]], 
    StyleBox[" ",
     FontColor->RGBColor[0.5, 0, 0.5]], 
    StyleBox["a",
     FontColor->RGBColor[0.5, 0, 0.5]], 
    StyleBox[" ",
     FontColor->RGBColor[0.5, 0, 0.5]], 
    StyleBox["trained",
     FontColor->RGBColor[0.5, 0, 0.5]], 
    StyleBox[" ",
     FontColor->RGBColor[0.5, 0, 0.5]], 
    StyleBox["SVM",
     FontColor->RGBColor[0.5, 0, 0.5]], " ", "like", " ", "libSVM"}], "*)"}], 
  RowBox[{"(*", " ", 
   RowBox[{
    RowBox[{
     RowBox[{"we", " ", "can", " ", "use", " ", "a", " ", "array"}], "-", 
     RowBox[{
     "like", " ", "func", " ", "group", " ", "to", " ", "describe", " ", 
      "it"}]}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"the", " ", "classify", " ", "func", " ", "is", " ", "y"}], "=", 
     RowBox[{"sign", 
      RowBox[{"(", 
       RowBox[{
        RowBox[{
         UnderscriptBox["\[Sum]", "i"], 
         RowBox[{"ai", " ", "yi", " ", "K", 
          RowBox[{"(", 
           RowBox[{"xi", ",", " ", "x"}], ")"}]}]}], " ", "+", " ", "b"}], 
       ")"}]}]}], ",", "\[IndentingNewLine]", 
    RowBox[{"symbol", " ", "must", " ", "be", " ", "local"}], ",", 
    RowBox[{
     RowBox[{"so", " ", "string", " ", "is", " ", "used", " ", 
      RowBox[{"here", ".", "\[IndentingNewLine]", "\"\<kernel\>\""}]}], "=", 
     "K"}], ",", " ", 
    RowBox[{"\"\<offset\>\"", "=", "b"}], ",", " ", 
    RowBox[{"\"\<alpha\>\"", "=", 
     RowBox[{
      RowBox[{"ai", "\[IndentingNewLine]", "\"\<svi\>\""}], "=", 
      RowBox[{"ai", " ", "*", " ", "yi"}]}]}], ",", " ", 
    RowBox[{"\"\<svX\>\"", "=", " ", 
     RowBox[{"X", "[", 
      RowBox[{"[", "sv", "]"}], "]"}]}], ",", " ", 
    RowBox[{"\"\<svY\>\"", "=", 
     RowBox[{
      RowBox[{
       RowBox[{"Y", "[", 
        RowBox[{"[", "sv", "]"}], "]"}], 
       RowBox[{"(", 
        RowBox[{"sv", "\[Equal]", 
         RowBox[{"ind", 
          RowBox[{"(", 
           RowBox[{"ai", "\[NotEqual]", "0"}], ")"}]}]}], ")"}], 
       "\[IndentingNewLine]", "\"\<opts\>\""}], "=", "opt"}]}], ",", "  ", 
    RowBox[{"\"\<label\>\"", " ", "=", " ", 
     RowBox[{"different", " ", "labels", " ", "of", " ", "classes"}]}]}], 
   "\[IndentingNewLine]", "\[IndentingNewLine]", "*)"}], 
  "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
    RowBox[{"how", " ", "to", " ", "deal", " ", "with", " ", 
     RowBox[{"errors", "."}]}], ":", "\[IndentingNewLine]", 
    RowBox[{
    "using", " ", "$Failed", " ", "if", " ", "possible", " ", "to", " ", 
     "indicate", " ", 
     RowBox[{"errors", "."}]}]}], "\[IndentingNewLine]", "*)"}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.511599676703125*^9}, {3.51166692153125*^9, 3.511666922125*^9}, {
   3.511668261703125*^9, 3.511668285953125*^9}, {3.511668730203125*^9, 
   3.511668732328125*^9}, {3.511675464734375*^9, 3.5116754671875*^9}, {
   3.511682987953125*^9, 3.51168300421875*^9}, {3.51168700184375*^9, 
   3.51168703459375*^9}, {3.5116937511875*^9, 3.511693752109375*^9}, {
   3.511694209046875*^9, 3.51169422590625*^9}, {3.511694543015625*^9, 
   3.5116945625625*^9}, {3.511695518296875*^9, 3.511695577984375*^9}, {
   3.511695739640625*^9, 3.51169577771875*^9}, {3.511738262375*^9, 
   3.511738263078125*^9}, {3.511758757828125*^9, 3.51175879121875*^9}, 
   3.511758920921875*^9, {3.511759137625*^9, 3.511759157125*^9}, {
   3.511759189765625*^9, 3.511759209984375*^9}, {3.511759312625*^9, 
   3.511759355*^9}, {3.511759526265625*^9, 3.5117595561875*^9}, {
   3.51175960209375*^9, 3.51175960303125*^9}, {3.511760448484375*^9, 
   3.511760458765625*^9}, {3.511770988125*^9, 3.511770999953125*^9}, {
   3.51177120803125*^9, 3.51177126578125*^9}, {3.511771320921875*^9, 
   3.511771383046875*^9}, {3.511771653625*^9, 3.51177165590625*^9}, {
   3.51177176896875*^9, 3.511771780015625*^9}, {3.51177193303125*^9, 
   3.511772005375*^9}, {3.51177531684375*^9, 3.511775420171875*^9}, {
   3.511777269640625*^9, 3.511777276875*^9}, {3.51177874584375*^9, 
   3.511778803328125*^9}, {3.511784526203125*^9, 3.51178455621875*^9}, {
   3.511826439921875*^9, 3.51182645859375*^9}, {3.511826586078125*^9, 
   3.511826592515625*^9}, {3.51182680503125*^9, 3.511826843921875*^9}, {
   3.511827053328125*^9, 3.511827060953125*^9}, {3.511840247234375*^9, 
   3.511840247828125*^9}, {3.511841357390625*^9, 3.51184138159375*^9}, {
   3.511842068*^9, 3.511842094203125*^9}, {3.511843263015625*^9, 
   3.511843288421875*^9}, {3.511847997234375*^9, 3.51184800403125*^9}, {
   3.51184812665625*^9, 3.511848142734375*^9}, {3.511861106234375*^9, 
   3.511861126125*^9}, {3.51192662025*^9, 3.511926632546875*^9}, 
   3.512103416375*^9, {3.512103455859375*^9, 3.51210349109375*^9}}]
}, Closed]],

Cell[CellGroupData[{

Cell[" ", "Subsection",
 CellChangeTimes->{{3.512031203625*^9, 3.512031209265625*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
    RowBox[{"TODO", ":", "\[IndentingNewLine]", 
     RowBox[{"how", " ", "to", " ", "check", " ", "the", " ", "options"}]}], 
    ","}], "\[IndentingNewLine]", "\[IndentingNewLine]", "*)"}], 
  "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{"Begin", "[", "\"\<`PP`\>\"", "]"}], ";"}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.511599676703125*^9}, {3.51166692153125*^9, 3.511666922125*^9}, {
   3.511668261703125*^9, 3.511668285953125*^9}, {3.511668730203125*^9, 
   3.511668732328125*^9}, {3.511675464734375*^9, 3.5116754671875*^9}, {
   3.511682987953125*^9, 3.51168300421875*^9}, {3.51168700184375*^9, 
   3.51168703459375*^9}, {3.5116937511875*^9, 3.511693752109375*^9}, {
   3.511694209046875*^9, 3.51169422590625*^9}, {3.511694543015625*^9, 
   3.5116945625625*^9}, {3.511695518296875*^9, 3.511695577984375*^9}, {
   3.511695739640625*^9, 3.51169577771875*^9}, {3.511738262375*^9, 
   3.511738263078125*^9}, {3.511758757828125*^9, 3.51175879121875*^9}, 
   3.511758920921875*^9, {3.511759137625*^9, 3.511759157125*^9}, {
   3.511759189765625*^9, 3.511759209984375*^9}, {3.511759312625*^9, 
   3.511759355*^9}, {3.511759526265625*^9, 3.5117595561875*^9}, {
   3.51175960209375*^9, 3.51175960303125*^9}, {3.511760448484375*^9, 
   3.511760458765625*^9}, {3.511770988125*^9, 3.511770999953125*^9}, {
   3.51177120803125*^9, 3.51177126578125*^9}, {3.511771320921875*^9, 
   3.511771383046875*^9}, {3.511771653625*^9, 3.51177165590625*^9}, {
   3.51177176896875*^9, 3.511771780015625*^9}, {3.51177193303125*^9, 
   3.511772005375*^9}, {3.51177531684375*^9, 3.511775420171875*^9}, {
   3.511777269640625*^9, 3.511777276875*^9}, {3.51177874584375*^9, 
   3.511778803328125*^9}, {3.511784526203125*^9, 3.51178455621875*^9}, {
   3.511826439921875*^9, 3.51182645859375*^9}, {3.511826586078125*^9, 
   3.511826592515625*^9}, {3.51182680503125*^9, 3.511826843921875*^9}, {
   3.511827053328125*^9, 3.511827060953125*^9}, {3.511840247234375*^9, 
   3.511840247828125*^9}, {3.511841357390625*^9, 3.51184138159375*^9}, {
   3.511842068*^9, 3.511842094203125*^9}, {3.511843263015625*^9, 
   3.511843288421875*^9}, {3.511847997234375*^9, 3.51184800403125*^9}, {
   3.51184812665625*^9, 3.511848142734375*^9}, {3.511861106234375*^9, 
   3.511861126125*^9}, {3.51192662025*^9, 3.51192666503125*^9}, {
   3.51202134978125*^9, 3.51202135059375*^9}, 3.512031232546875*^9, 
   3.512036028375*^9, 3.512103451375*^9}]
}, Closed]]
}, Open  ]],

Cell[CellGroupData[{

Cell["codes", "Section",
 InitializationCell->True,
 CellChangeTimes->{{3.512028742109375*^9, 3.512028750390625*^9}}],

Cell[CellGroupData[{

Cell["main func", "Subsection",
 CellChangeTimes->{{3.51202956015625*^9, 3.512029570078125*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
    RowBox[{"like", " ", "libSVM"}], ",", " ", 
    RowBox[{"scale", " ", "data", " ", 
     RowBox[{"to", " ", "[", 
      RowBox[{
       RowBox[{"-", "1"}], ",", "1"}], "]"}], " ", "or", " ", "sth", " ", 
     "linearly"}]}], "*)"}], "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"SVMScale", "[", "]"}], ":=", 
     RowBox[{"Module", "[", 
      RowBox[{
       RowBox[{"{", "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"Return", "[", "\"\<not implemented\>\"", "]"}], ";"}]}], 
      "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"Options", "[", "SVMTrain", "]"}], "=", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"svmType", "\[Rule]", "1"}], ",", 
       RowBox[{"kernelType", "\[Rule]", "1"}], ",", 
       RowBox[{"qpType", "\[Rule]", "2"}], ",", 
       RowBox[{"t", "\[Rule]", "0.0001"}], ",", 
       RowBox[{"cost", "\[Rule]", 
        RowBox[{"{", 
         RowBox[{"1", ",", "1"}], "}"}]}], ",", 
       RowBox[{"nu", "\[Rule]", "0.5"}], ",", 
       RowBox[{"\[Gamma]", "\[Rule]", "0.1"}], ",", 
       RowBox[{"degree", "\[Rule]", "3"}], ",", 
       RowBox[{"coef0", "\[Rule]", "0"}]}], "}"}]}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"wrapper", " ", "SVM", " ", "train", " ", "func"}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"SVMTrain", "[", 
      RowBox[{
       RowBox[{"X_", "?", "MatrixQ"}], ",", "Y_List", ",", "opt___"}], "]"}], 
     ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"m", ",", "n", ",", "K", ",", "s"}], "}"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{"no", " ", "tensor", " ", "here"}], "*)"}], 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{
         RowBox[{"{", 
          RowBox[{"m", ",", "n"}], "}"}], "=", 
         RowBox[{"Dimensions", "[", "X", "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{
           RowBox[{"Length", "[", "Y", "]"}], "\[NotEqual]", "m"}], ",", 
          RowBox[{
           RowBox[{"Print", "[", "\"\<x and y dim error\>\"", "]"}], ";", 
           RowBox[{"Return", "[", "]"}]}]}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"SetOptions", "[", 
         RowBox[{"SVMTrain", ",", 
          RowBox[{"\[Gamma]", "\[Rule]", 
           RowBox[{"1", "/", "n"}]}]}], "]"}], ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{"which", " ", "kernel"}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{"K", "=", 
         RowBox[{"Switch", "[", 
          RowBox[{
           RowBox[{"(", 
            RowBox[{
             RowBox[{"kernelType", "/.", 
              RowBox[{"{", "opt", "}"}]}], "/.", 
             RowBox[{"Options", "[", "SVMTrain", "]"}]}], ")"}], ",", 
           "\[IndentingNewLine]", "1", ",", "IdentityKernel", ",", 
           "\[IndentingNewLine]", "2", ",", 
           RowBox[{
            RowBox[{
             RowBox[{
              RowBox[{"PolynomialKernel", "[", 
               RowBox[{
               "#1", ",", "#2", ",", "\[Gamma]", ",", "degree", ",", 
                "coef0"}], "]"}], "&"}], "/.", 
             RowBox[{"{", "opt", "}"}]}], "/.", 
            RowBox[{"Options", "[", "SVMTrain", "]"}]}], ",", 
           "\[IndentingNewLine]", "3", ",", 
           RowBox[{
            RowBox[{
             RowBox[{
              RowBox[{"RBFKernel", "[", 
               RowBox[{"#1", ",", "#2", ",", "\[Gamma]"}], "]"}], "&"}], "/.", 
             RowBox[{"{", "opt", "}"}]}], "/.", 
            RowBox[{"Options", "[", "SVMTrain", "]"}]}], ",", 
           "\[IndentingNewLine]", "_", ",", 
           RowBox[{
            RowBox[{"Print", "[", "\"\<kernelType error, exit.\>\"", "]"}], 
            ";", 
            RowBox[{"Return", "[", "$Failed", "]"}], ";"}]}], 
          "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "\"\<SVM train begin\>\"", "]"}], ";"}], 
         "*)"}], "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
         "svm", " ", "is", " ", "built", " ", "in", " ", "the", " ", 
          "specific", " ", "implementation"}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{"s", "=", 
         RowBox[{"Switch", "[", 
          RowBox[{
           RowBox[{"(", 
            RowBox[{
             RowBox[{"svmType", "/.", 
              RowBox[{"{", "opt", "}"}]}], "/.", 
             RowBox[{"Options", "[", "SVMTrain", "]"}]}], ")"}], ",", 
           "\[IndentingNewLine]", "1", ",", 
           RowBox[{"oSVM", "[", 
            RowBox[{"X", ",", "Y", ",", "K", ",", "opt"}], "]"}], ",", 
           "\[IndentingNewLine]", "2", ",", 
           RowBox[{"cSVM", "[", 
            RowBox[{"X", ",", "Y", ",", "K", ",", "opt"}], "]"}], ",", 
           "\[IndentingNewLine]", "3", ",", 
           RowBox[{
            RowBox[{"SetOptions", "[", 
             RowBox[{"SVMTrain", ",", 
              RowBox[{"qpType", "\[Rule]", "3"}]}], "]"}], ";", 
            RowBox[{"nuSVM", "[", 
             RowBox[{"X", ",", "Y", ",", "K", ",", "opt"}], "]"}]}], ",", 
           "\[IndentingNewLine]", "_", ",", 
           RowBox[{
            RowBox[{"Print", "[", "\"\<svmType error, exit.\>\"", "]"}], ";", 
            RowBox[{"Return", "[", "$Failed", "]"}], ";"}]}], 
          "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"s", "\[Equal]", "$Failed"}], ",", 
          RowBox[{
           RowBox[{"Print", "[", "\"\<SVM train error\>\"", "]"}], ";", 
           RowBox[{"Return", "[", "$Failed", "]"}]}]}], "]"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"TODO", " ", ":", " ", 
           RowBox[{
            RowBox[{"although", " ", "only", " ", "2"}], "-", 
            RowBox[{"class", " ", "implimented"}]}]}], ",", " ", 
          RowBox[{
          "label", " ", "and", " ", "groups", " ", "are", " ", "found", " ", 
           "from", " ", "Y"}]}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"s", "[", "\"\<label\>\"", "]"}], "=", 
         RowBox[{"Union", "[", "Y", "]"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{
           RowBox[{"SVM", "[", "\"\<kernel\>\"", "]"}], "=", "K"}], ";"}], 
         "*)"}], "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"s", "[", "\"\<opts\>\"", "]"}], "=", "opt"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "s"}]}], 
      "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", 
   "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{
      RowBox[{"s", " ", "saved", " ", "SVM"}], ";", " ", 
      RowBox[{"data", " ", "to", " ", "classify"}]}], ",", " ", 
     RowBox[{"must", " ", "be", " ", "a", " ", "matrix"}]}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{
     "save", " ", "a", " ", "func", " ", "in", " ", "SVM", " ", "is", " ", 
      "not", " ", "good"}], ",", " ", 
     RowBox[{"so", " ", "the", " ", "opt", " ", "counts"}]}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"SVMClassify", "[", 
      RowBox[{"s_", ",", 
       RowBox[{"data_", "?", "MatrixQ"}]}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"K", ",", "f", ",", "r", ",", "rl", ",", "opt"}], "}"}], ",", 
       "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"opt", "=", 
         RowBox[{"s", "[", "\"\<opts\>\"", "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"K", "=", 
         RowBox[{"Switch", "[", 
          RowBox[{
           RowBox[{"(", 
            RowBox[{
             RowBox[{"kernelType", "/.", 
              RowBox[{"{", "opt", "}"}]}], "/.", 
             RowBox[{"Options", "[", "SVMTrain", "]"}]}], ")"}], ",", 
           "\[IndentingNewLine]", "1", ",", "IdentityKernel", ",", 
           "\[IndentingNewLine]", "2", ",", 
           RowBox[{
            RowBox[{
             RowBox[{
              RowBox[{"PolynomialKernel", "[", 
               RowBox[{
               "#1", ",", "#2", ",", "\[Gamma]", ",", "degree", ",", 
                "coef0"}], "]"}], "&"}], "/.", 
             RowBox[{"{", "opt", "}"}]}], "/.", 
            RowBox[{"Options", "[", "SVMTrain", "]"}]}], ",", 
           "\[IndentingNewLine]", "3", ",", 
           RowBox[{
            RowBox[{
             RowBox[{
              RowBox[{"RBFKernel", "[", 
               RowBox[{"#1", ",", "#2", ",", "\[Gamma]"}], "]"}], "&"}], "/.", 
             RowBox[{"{", "opt", "}"}]}], "/.", 
            RowBox[{"Options", "[", "SVMTrain", "]"}]}], ",", 
           "\[IndentingNewLine]", "_", ",", 
           RowBox[{
            RowBox[{"Print", "[", "\"\<kernelType error, exit.\>\"", "]"}], 
            ";", 
            RowBox[{"Return", "[", "$Failed", "]"}], ";"}]}], 
          "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"K", "=", 
           RowBox[{"s", "[", "\"\<kernel\>\"", "]"}]}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"\[Alpha]", "=", 
           RowBox[{"s", "[", "\"\<alpha\>\"", "]"}]}], ";"}], "*)"}], 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"f", "[", "x_", "]"}], ":=", 
         RowBox[{
          RowBox[{
           RowBox[{"s", "[", "\"\<svi\>\"", "]"}], ".", 
           RowBox[{"Map", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"K", "[", 
               RowBox[{"#", ",", "x"}], "]"}], "&"}], ",", 
             RowBox[{"s", "[", "\"\<svX\>\"", "]"}]}], "]"}]}], "+", 
          RowBox[{"s", "[", "\"\<offset\>\"", "]"}]}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"r", "=", 
         RowBox[{"Map", "[", 
          RowBox[{"f", ",", "data"}], "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"TODO", ":", " ", 
           RowBox[{
            RowBox[{
             RowBox[{"change", ".", " ", "NOW"}], " ", "2"}], "-", 
            RowBox[{"class", " ", "only"}]}]}], ",", "\[IndentingNewLine]", 
          RowBox[{
           RowBox[{"make", " ", "it", " ", "VF"}], "-", "compatible"}]}], 
         "*)"}], "\[IndentingNewLine]", 
        RowBox[{"rl", "=", 
         RowBox[{"Sign", "[", "r", "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"{", 
         RowBox[{"r", ",", "rl"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}], 
    ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"save", " ", "a", " ", "SVM", " ", "in", " ", "a", " ", "file"}], 
    "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"SVMSave", "[", 
      RowBox[{"s_", ",", 
       RowBox[{"fn_:", "\"\<\>\""}]}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", "f", "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"fn", "\[Equal]", "\"\<\>\""}], ",", "\[IndentingNewLine]", 
          RowBox[{"f", "=", 
           RowBox[{"\"\<..\\\\tmp\\\\\>\"", "<>", "\"\<svm.mx\>\""}]}], ",", 
          RowBox[{"f", "=", "fn"}]}], "]"}], ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"At", " ", "the", " ", "moment"}], ",", " ", 
          RowBox[{"merely", " ", "save", " ", "it"}]}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"Export", "[", 
         RowBox[{"f", ",", "s"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], 
    ";"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"SVMLoad", "[", 
      RowBox[{"fn_:", "\"\<\>\""}], "]"}], ":=", 
     RowBox[{"Module", "[", 
      RowBox[{
       RowBox[{"{", "f", "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"fn", "\[Equal]", "\"\<\>\""}], ",", "\[IndentingNewLine]", 
          RowBox[{"f", "=", 
           RowBox[{"\"\<..\\\\tmp\\\\\>\"", "<>", "\"\<svm.mx\>\""}]}], ",", 
          RowBox[{"f", "=", "fn"}]}], "]"}], ";", "\[IndentingNewLine]", 
        RowBox[{"Import", "[", "f", "]"}]}]}], "\[IndentingNewLine]", "]"}]}],
     ";"}]}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.51159968415625*^9}, {3.51159972271875*^9, 3.511599772671875*^9}, {
   3.511599851640625*^9, 3.51159986265625*^9}, {3.511606746859375*^9, 
   3.511606808875*^9}, {3.511606888890625*^9, 3.511607087453125*^9}, {
   3.511668746265625*^9, 3.511668779765625*^9}, {3.511669289859375*^9, 
   3.511669365328125*^9}, {3.51167452465625*^9, 3.511674532765625*^9}, {
   3.51167541496875*^9, 3.51167542659375*^9}, 3.511676043890625*^9, {
   3.51167614634375*^9, 3.5116761631875*^9}, {3.511693586578125*^9, 
   3.511693586875*^9}, {3.511693678515625*^9, 3.511693680453125*^9}, 
   3.51169371796875*^9, {3.51169579890625*^9, 3.511695882671875*^9}, {
   3.511758938203125*^9, 3.511759000734375*^9}, {3.51177169909375*^9, 
   3.511771738828125*^9}, {3.511771784921875*^9, 3.511771787359375*^9}, {
   3.511774793171875*^9, 3.511774810203125*^9}, {3.511774960171875*^9, 
   3.51177496746875*^9}, {3.51177529671875*^9, 3.511775307453125*^9}, {
   3.511775651671875*^9, 3.511775666484375*^9}, {3.511776013734375*^9, 
   3.511776027609375*^9}, {3.51177621859375*^9, 3.51177631053125*^9}, {
   3.511776500125*^9, 3.51177652971875*^9}, {3.511777129890625*^9, 
   3.51177721575*^9}, {3.511777258359375*^9, 3.51177734090625*^9}, {
   3.51177796175*^9, 3.511777964109375*^9}, {3.511779130515625*^9, 
   3.51177913121875*^9}, {3.511779253828125*^9, 3.511779275765625*^9}, {
   3.511779314578125*^9, 3.511779359140625*^9}, {3.51177985434375*^9, 
   3.51177989053125*^9}, {3.511780793171875*^9, 3.511780857078125*^9}, {
   3.511781254859375*^9, 3.511781266609375*^9}, 3.511781307375*^9, 
   3.511781425078125*^9, {3.51178191071875*^9, 3.511781953296875*^9}, {
   3.511782096546875*^9, 3.511782115265625*^9}, 3.51178224353125*^9, {
   3.511825637671875*^9, 3.511825693375*^9}, {3.511825854296875*^9, 
   3.5118258548125*^9}, {3.511825918140625*^9, 3.511825920234375*^9}, {
   3.511825981*^9, 3.5118261099375*^9}, {3.511826141484375*^9, 
   3.511826150515625*^9}, {3.511826559640625*^9, 3.511826575453125*^9}, {
   3.51182667821875*^9, 3.511826679734375*^9}, 3.5118268663125*^9, {
   3.511840573484375*^9, 3.511840656*^9}, {3.51184070734375*^9, 
   3.511840816453125*^9}, {3.5118408734375*^9, 3.511840884515625*^9}, {
   3.51184095059375*^9, 3.51184097396875*^9}, {3.511842050234375*^9, 
   3.51184206053125*^9}, {3.511842332203125*^9, 3.51184248478125*^9}, {
   3.511842634203125*^9, 3.51184264621875*^9}, 3.51184279984375*^9, {
   3.5118428323125*^9, 3.511842929875*^9}, {3.511843059640625*^9, 
   3.51184308296875*^9}, 3.51184314015625*^9, {3.511843200953125*^9, 
   3.511843203796875*^9}, {3.51184323653125*^9, 3.511843252859375*^9}, {
   3.511843360828125*^9, 3.511843378453125*^9}, {3.5118434105*^9, 
   3.511843494359375*^9}, {3.511843696828125*^9, 3.511843751234375*^9}, {
   3.51184740690625*^9, 3.511847449640625*^9}, {3.5118476741875*^9, 
   3.5118476770625*^9}, {3.511847749109375*^9, 3.5118478575*^9}, {
   3.51184797246875*^9, 3.5118479921875*^9}, {3.51185633946875*^9, 
   3.51185636353125*^9}, {3.511856413609375*^9, 3.511856417328125*^9}, {
   3.511857368875*^9, 3.511857434640625*^9}, {3.5118588500625*^9, 
   3.511858896609375*^9}, {3.5118594165625*^9, 3.511859466125*^9}, {
   3.5118596959375*^9, 3.511859712296875*^9}, {3.51185988634375*^9, 
   3.51185989721875*^9}, {3.511859989734375*^9, 3.511860029265625*^9}, {
   3.511860455640625*^9, 3.51186045803125*^9}, {3.51186068103125*^9, 
   3.511860709359375*^9}, {3.511860804125*^9, 3.511860813640625*^9}, {
   3.5118609459375*^9, 3.511860953453125*^9}, {3.511861313109375*^9, 
   3.511861357578125*^9}, {3.511861427734375*^9, 3.511861501265625*^9}, {
   3.5118617790625*^9, 3.511861785328125*^9}, {3.511861870875*^9, 
   3.51186191278125*^9}, {3.511862084640625*^9, 3.51186212053125*^9}, {
   3.51186220221875*^9, 3.511862210578125*^9}, {3.511862312859375*^9, 
   3.511862313984375*^9}, {3.511862760515625*^9, 3.511862770421875*^9}, {
   3.5119106066875*^9, 3.511910617328125*^9}, {3.511926275078125*^9, 
   3.51192632978125*^9}, {3.511926476296875*^9, 3.511926514015625*^9}, {
   3.511926609609375*^9, 3.511926611578125*^9}, {3.511926735734375*^9, 
   3.511926750265625*^9}, {3.511926811984375*^9, 3.5119268130625*^9}, 
   3.51192715771875*^9, {3.51202916265625*^9, 3.512029189296875*^9}, {
   3.51203591653125*^9, 3.512035987125*^9}, 3.51203606496875*^9, {
   3.51210398359375*^9, 3.512103983875*^9}, {3.512188161078125*^9, 
   3.512188167390625*^9}, 3.512188306578125*^9, {3.512188356078125*^9, 
   3.51218843965625*^9}, {3.512189755546875*^9, 3.5121897558125*^9}, {
   3.51219068446875*^9, 3.5121906966875*^9}, {3.512192305921875*^9, 
   3.512192308046875*^9}, {3.512294511421875*^9, 3.512294521328125*^9}, {
   3.5122950210625*^9, 3.512295057234375*^9}, {3.51229509553125*^9, 
   3.512295099140625*^9}, 3.5122953919375*^9, 3.512364660484375*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", "Visualization", "*)"}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
    RowBox[{
    "X", " ", "is", " ", "the", " ", "data", " ", "points", " ", "ploted"}], 
    ",", " ", 
    RowBox[{"Y", " ", "is", " ", "the", " ", "label", " ", "of", " ", "X"}]}],
    "*)"}], "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"SVMPlot", "[", 
      RowBox[{"s_", ",", "X_", ",", 
       RowBox[{"Y_:", 
        RowBox[{"{", "}"}]}]}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
        "K", ",", "opt", ",", "f", ",", "dim", ",", "sv", ",", "x1", ",", 
         "x2", ",", "x3"}], "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"opt", "=", 
         RowBox[{"s", "[", "\"\<opts\>\"", "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"K", "=", 
         RowBox[{"Switch", "[", 
          RowBox[{
           RowBox[{"(", 
            RowBox[{
             RowBox[{"kernelType", "/.", 
              RowBox[{"{", "opt", "}"}]}], "/.", 
             RowBox[{"Options", "[", "SVMTrain", "]"}]}], ")"}], ",", 
           "\[IndentingNewLine]", "1", ",", "IdentityKernel", ",", 
           "\[IndentingNewLine]", "2", ",", 
           RowBox[{
            RowBox[{
             RowBox[{
              RowBox[{"PolynomialKernel", "[", 
               RowBox[{
               "#1", ",", "#2", ",", "\[Gamma]", ",", "degree", ",", 
                "coef0"}], "]"}], "&"}], "/.", 
             RowBox[{"{", "opt", "}"}]}], "/.", 
            RowBox[{"Options", "[", "SVMTrain", "]"}]}], ",", 
           "\[IndentingNewLine]", "3", ",", 
           RowBox[{
            RowBox[{
             RowBox[{
              RowBox[{"RBFKernel", "[", 
               RowBox[{"#1", ",", "#2", ",", "\[Gamma]"}], "]"}], "&"}], "/.", 
             RowBox[{"{", "opt", "}"}]}], "/.", 
            RowBox[{"Options", "[", "SVMTrain", "]"}]}], ",", 
           "\[IndentingNewLine]", "_", ",", 
           RowBox[{
            RowBox[{"Print", "[", "\"\<kernelType error, exit.\>\"", "]"}], 
            ";", 
            RowBox[{"Return", "[", "$Failed", "]"}]}]}], 
          "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"first", " ", "check", " ", "dim"}], ",", " ", 
          RowBox[{
          "dim", " ", "must", " ", "be", " ", "2", " ", "or", " ", "3"}]}], 
         "*)"}], "\[IndentingNewLine]", 
        RowBox[{"dim", "=", 
         RowBox[{"Length", "[", 
          RowBox[{
           RowBox[{"s", "[", "\"\<svX\>\"", "]"}], "[", 
           RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{
           RowBox[{"dim", ">", "3"}], "||", 
           RowBox[{"dim", "<", "2"}]}], ",", 
          RowBox[{"Return", "[", "$Failed", "]"}]}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"Y", "\[NotEqual]", 
           RowBox[{"{", "}"}]}], ",", "\n", "   ", 
          RowBox[{
           RowBox[{"1", "==", "1"}], ";"}]}], "\[IndentingNewLine]", "]"}], 
        ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", 
           RowBox[{"x1range", ",", "x2range", ",", "x3range"}], "]"}], ";"}], 
         "*)"}], "\n", "   ", 
        RowBox[{"f", "=", 
         RowBox[{
          RowBox[{
           RowBox[{"s", "[", "\"\<svi\>\"", "]"}], ".", 
           RowBox[{"Map", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"K", "[", 
               RowBox[{"#", ",", 
                RowBox[{"{", 
                 RowBox[{"x1", ",", "x2", ",", "x3"}], "}"}]}], "]"}], "&"}], 
             ",", 
             RowBox[{"s", "[", "\"\<svX\>\"", "]"}]}], "]"}]}], "+", 
          RowBox[{"s", "[", "\"\<offset\>\"", "]"}]}]}], ";", 
        "\[IndentingNewLine]", "\n", "    ", 
        RowBox[{"Show", "[", "\n", "      ", 
         RowBox[{
          RowBox[{"ListPointPlot3D", "[", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{
              RowBox[{"s", "[", "\"\<svX\>\"", "]"}], ",", "X"}], "}"}], ",", 
            RowBox[{"PlotStyle", "->", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{"Hue", "[", "0.6", "]"}], ",", 
               RowBox[{"PointSize", "[", "Large", "]"}]}], "}"}]}]}], "]"}], 
          ",", "\n", "    ", 
          RowBox[{"(*", "  ", 
           RowBox[{
            RowBox[{"ListPlot", "[", 
             RowBox[{"Extract", "[", 
              RowBox[{"X", ",", 
               RowBox[{"Position", "[", 
                RowBox[{"y", ",", "1"}], "]"}]}], "]"}], "]"}], ",", "\n", 
            "      ", 
            RowBox[{"ListPlot", "[", 
             RowBox[{
              RowBox[{"Extract", "[", 
               RowBox[{"X", ",", 
                RowBox[{"Position", "[", 
                 RowBox[{"y", ",", 
                  RowBox[{"-", "1"}]}], "]"}]}], "]"}], ",", 
              RowBox[{"PlotStyle", "->", 
               RowBox[{"{", 
                RowBox[{"GrayLevel", "[", "0.6", "]"}], "}"}]}]}], "]"}], 
            ","}], "*)"}], "\n", "      ", 
          RowBox[{"ContourPlot3D", "[", 
           RowBox[{
            RowBox[{"f", "==", "0"}], ",", 
            RowBox[{"{", 
             RowBox[{"x1", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"x2", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"x3", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "3"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "3"}], "]"}], "]"}], "]"}]}], "}"}]}], 
           "]"}], ",", "\n", "      ", 
          RowBox[{"ContourPlot3D", "[", 
           RowBox[{
            RowBox[{"f", "==", "1"}], ",", 
            RowBox[{"{", 
             RowBox[{"x1", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"x2", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"x3", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "3"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "3"}], "]"}], "]"}], "]"}]}], "}"}]}], 
           RowBox[{"(*", 
            RowBox[{"PlotStyle", "->", 
             RowBox[{"Dashing", "[", 
              RowBox[{"{", 
               RowBox[{".01", ",", ".01"}], "}"}], "]"}]}], "*)"}], "]"}], 
          ",", "\n", "      ", 
          RowBox[{"ContourPlot3D", "[", 
           RowBox[{
            RowBox[{"f", "==", 
             RowBox[{"-", "1"}]}], ",", 
            RowBox[{"{", 
             RowBox[{"x1", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"x2", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"x3", ",", 
              RowBox[{"Min", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "3"}], "]"}], "]"}], "]"}], ",", 
              RowBox[{"Max", "[", 
               RowBox[{"X", "[", 
                RowBox[{"[", 
                 RowBox[{"All", ",", "3"}], "]"}], "]"}], "]"}]}], "}"}]}], 
           RowBox[{"(*", 
            RowBox[{
             RowBox[{"PlotStyle", "->", 
              RowBox[{"Dashing", "[", 
               RowBox[{"{", 
                RowBox[{".01", ",", ".01"}], "}"}], "]"}]}], "]"}], "*)"}], 
           "]"}], ",", 
          RowBox[{"BoxRatios", "\[Rule]", "Automatic"}]}], 
         "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], 
    ";"}], "\[IndentingNewLine]"}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.51159968415625*^9}, {3.51159972271875*^9, 3.511599772671875*^9}, {
   3.511599851640625*^9, 3.51159986265625*^9}, {3.511606746859375*^9, 
   3.511606808875*^9}, {3.511606888890625*^9, 3.511607087453125*^9}, {
   3.511668746265625*^9, 3.511668779765625*^9}, {3.511669289859375*^9, 
   3.511669365328125*^9}, {3.51167452465625*^9, 3.511674532765625*^9}, {
   3.51167541496875*^9, 3.51167542659375*^9}, 3.511676043890625*^9, {
   3.51167614634375*^9, 3.5116761631875*^9}, {3.511693586578125*^9, 
   3.511693586875*^9}, {3.511693678515625*^9, 3.511693680453125*^9}, 
   3.51169371796875*^9, {3.51169579890625*^9, 3.511695882671875*^9}, {
   3.511758938203125*^9, 3.511759000734375*^9}, {3.51177169909375*^9, 
   3.511771738828125*^9}, {3.511771784921875*^9, 3.511771787359375*^9}, {
   3.511774793171875*^9, 3.511774810203125*^9}, {3.511774960171875*^9, 
   3.51177496746875*^9}, {3.51177529671875*^9, 3.511775307453125*^9}, {
   3.511775651671875*^9, 3.511775666484375*^9}, {3.511776013734375*^9, 
   3.511776027609375*^9}, {3.51177621859375*^9, 3.51177631053125*^9}, {
   3.511776500125*^9, 3.51177652971875*^9}, {3.511777129890625*^9, 
   3.51177721575*^9}, {3.511777258359375*^9, 3.51177734090625*^9}, {
   3.51177796175*^9, 3.511777964109375*^9}, {3.511779130515625*^9, 
   3.51177913121875*^9}, {3.511779253828125*^9, 3.511779275765625*^9}, {
   3.511779314578125*^9, 3.511779359140625*^9}, {3.51177985434375*^9, 
   3.51177989053125*^9}, {3.511780793171875*^9, 3.511780857078125*^9}, {
   3.511781254859375*^9, 3.511781266609375*^9}, 3.511781307375*^9, 
   3.511781425078125*^9, {3.51178191071875*^9, 3.511781953296875*^9}, {
   3.511782096546875*^9, 3.511782115265625*^9}, 3.51178224353125*^9, {
   3.511825637671875*^9, 3.511825693375*^9}, {3.511825854296875*^9, 
   3.5118258548125*^9}, {3.511825918140625*^9, 3.511825920234375*^9}, {
   3.511825981*^9, 3.5118261099375*^9}, {3.511826141484375*^9, 
   3.511826150515625*^9}, {3.511826559640625*^9, 3.511826575453125*^9}, {
   3.51182667821875*^9, 3.511826679734375*^9}, 3.5118268663125*^9, {
   3.511840573484375*^9, 3.511840656*^9}, {3.51184070734375*^9, 
   3.511840816453125*^9}, {3.5118408734375*^9, 3.511840884515625*^9}, {
   3.51184095059375*^9, 3.51184097396875*^9}, {3.511842050234375*^9, 
   3.51184206053125*^9}, {3.511842332203125*^9, 3.51184248478125*^9}, {
   3.511842634203125*^9, 3.51184264621875*^9}, 3.51184279984375*^9, {
   3.5118428323125*^9, 3.511842929875*^9}, {3.511843059640625*^9, 
   3.51184308296875*^9}, 3.51184314015625*^9, {3.511843200953125*^9, 
   3.511843203796875*^9}, {3.51184323653125*^9, 3.511843252859375*^9}, {
   3.511843360828125*^9, 3.511843378453125*^9}, {3.5118434105*^9, 
   3.511843494359375*^9}, {3.511843696828125*^9, 3.511843751234375*^9}, {
   3.51184740690625*^9, 3.511847449640625*^9}, {3.5118476741875*^9, 
   3.5118476770625*^9}, {3.511847749109375*^9, 3.5118478575*^9}, {
   3.51184797246875*^9, 3.5118479921875*^9}, {3.51185633946875*^9, 
   3.51185636353125*^9}, {3.511856413609375*^9, 3.511856417328125*^9}, {
   3.511857368875*^9, 3.511857434640625*^9}, {3.5118588500625*^9, 
   3.511858896609375*^9}, {3.5118594165625*^9, 3.511859466125*^9}, {
   3.5118596959375*^9, 3.511859712296875*^9}, {3.51185988634375*^9, 
   3.51185989721875*^9}, {3.511859989734375*^9, 3.511860029265625*^9}, {
   3.511860455640625*^9, 3.51186045803125*^9}, {3.51186068103125*^9, 
   3.511860709359375*^9}, {3.511860804125*^9, 3.511860813640625*^9}, {
   3.5118609459375*^9, 3.511860953453125*^9}, {3.511861313109375*^9, 
   3.511861357578125*^9}, {3.511861427734375*^9, 3.511861501265625*^9}, {
   3.5118617790625*^9, 3.511861785328125*^9}, {3.511861870875*^9, 
   3.51186191278125*^9}, {3.511862084640625*^9, 3.51186212053125*^9}, {
   3.51186220221875*^9, 3.511862210578125*^9}, {3.511862312859375*^9, 
   3.511862313984375*^9}, {3.511862760515625*^9, 3.511862770421875*^9}, {
   3.5119106066875*^9, 3.51191062646875*^9}, {3.511910684640625*^9, 
   3.51191073646875*^9}, {3.511910773984375*^9, 3.511910803703125*^9}, {
   3.511910895734375*^9, 3.511910929984375*^9}, {3.51191099528125*^9, 
   3.511911150109375*^9}, {3.511911181953125*^9, 3.511911201*^9}, {
   3.511911235515625*^9, 3.511911592171875*^9}, {3.51191172184375*^9, 
   3.511911729078125*^9}, {3.5119117615625*^9, 3.51191180196875*^9}, {
   3.51191186309375*^9, 3.51191187440625*^9}, {3.511911978421875*^9, 
   3.5119119874375*^9}, {3.511912074265625*^9, 3.511912078453125*^9}, {
   3.511912113078125*^9, 3.5119121205*^9}, {3.5119122361875*^9, 
   3.5119122464375*^9}, {3.511912294390625*^9, 3.51191230128125*^9}, {
   3.511912836171875*^9, 3.5119128403125*^9}, {3.511912874546875*^9, 
   3.511912877171875*^9}, {3.5119129935*^9, 3.51191306171875*^9}, {
   3.51191332571875*^9, 3.511913326203125*^9}, {3.51191341046875*^9, 
   3.51191343190625*^9}, {3.511926820703125*^9, 3.511926821671875*^9}, {
   3.512036076640625*^9, 3.512036152796875*^9}, {3.512036189046875*^9, 
   3.512036209625*^9}}]
}, Open  ]],

Cell[CellGroupData[{

Cell["kernel funcs ", "Subsection",
 CellChangeTimes->{{3.5120295896875*^9, 3.512029601296875*^9}, 
   3.512029735625*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
   "There", " ", "are", " ", "different", " ", "kernels", " ", "and", " ", 
    "dfferent", " ", "SVMs"}], "*)"}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
    StyleBox["kernels",
     FontColor->RGBColor[0.5, 0, 0.5]], ",", " ", 
    RowBox[{"dots", " ", "apply", " ", "to", " ", "list", " ", 
     RowBox[{"only", "!!"}], "all", " ", "default", " ", "values", " ", "are",
      " ", "same", " ", "as", " ", "libSVM"}]}], "*)"}], 
  "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"IdentityKernel", "[", 
      RowBox[{"x_List", ",", "y_List"}], "]"}], "=", 
     RowBox[{"x", ".", "y"}]}], ";"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"\[Gamma]", ">", "0"}], "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"RBFKernel", "[", 
      RowBox[{"x_", ",", "y_", ",", "\[Gamma]_"}], "]"}], "=", 
     SuperscriptBox["\[ExponentialE]", 
      RowBox[{
       RowBox[{"-", "\[Gamma]"}], 
       RowBox[{
        RowBox[{"(", 
         RowBox[{"x", "-", "y"}], ")"}], ".", 
        RowBox[{"(", 
         RowBox[{"x", "-", "y"}], ")"}]}]}]]}], ";"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"d", " ", "\[Element]", " ", "\[DoubleStruckCapitalZ]"}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"PolynomialKernel", "[", 
      RowBox[{
      "x_", ",", "y_", ",", "\[Gamma]_", ",", "d_Integer", ",", "c_"}], "]"}],
      "=", 
     SuperscriptBox[
      RowBox[{"(", 
       RowBox[{
        RowBox[{"\[Gamma]", " ", 
         RowBox[{"x", ".", "y"}]}], "+", "c"}], ")"}], "d"]}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", "sigmoid", "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"SigmoidKernel", "[", 
      RowBox[{"x_", ",", "y_", ",", "\[Gamma]_", ",", "c_"}], "]"}], "=", 
     RowBox[{"Tanh", "[", 
      RowBox[{
       RowBox[{"\[Gamma]", " ", 
        RowBox[{"x", ".", "y"}]}], "+", "c"}], "]"}]}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{"Vovk", "'"}], "s", " ", "real", " ", "infinity", " ", 
     "polynomial", " ", "universal", " ", "kernel"}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"VovkPolynomialKernel", "[", 
      RowBox[{"x_", ",", "y_", ",", "d_Integer"}], "]"}], "=", 
     SuperscriptBox[
      RowBox[{"(", 
       RowBox[{"1", "-", 
        RowBox[{"x", " ", "z"}]}], ")"}], 
      RowBox[{"-", "d"}]]}], ";"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{"0", "<", 
      StyleBox["q",
       FontSlant->"Italic"], " ", "<", 
      RowBox[{"1", " ", "and", " ", "all", " ", 
       StyleBox[
        RowBox[{"compact", 
         StyleBox["X",
          FontSlant->"Italic"]}]]}]}], 
     StyleBox[" ",
      FontSlant->"Italic"], 
     StyleBox["\[Subset]",
      FontSize->14], 
     StyleBox[" ",
      FontSize->14], 
     FormBox[
      SuperscriptBox[
       RowBox[{"[", 
        RowBox[{"0", ",", " ", 
         RowBox[{"2", " ", "\[Pi]"}]}], " ", ")"}], 
       RowBox[{" ", "n"}]],
      TraditionalForm]}], "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"FourierKernel", "[", 
      RowBox[{"x_", ",", "y_", ",", "q_"}], "]"}], "=", 
     FractionBox[
      RowBox[{"1", "-", 
       SuperscriptBox["q", "2"]}], 
      RowBox[{"2", " ", 
       RowBox[{"(", 
        RowBox[{"1", "-", 
         RowBox[{"2", " ", "q", " ", 
          RowBox[{"Cos", "[", 
           RowBox[{"x", "-", "y"}], "]"}]}], "+", 
         SuperscriptBox["q", "2"]}], ")"}]}]]}], ";"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{"Wavelet", " ", "kernel", " ", "with", " ", 
      StyleBox["a",
       FontSlant->"Italic"]}], " ", "\[Element]", 
     RowBox[{
      SuperscriptBox[
       StyleBox["\[DoubleStruckCapitalR]",
        FontSize->14,
        FontSlant->"Italic"], 
       RowBox[{" ", "1"}]], "and", " ", "all", " ", 
      StyleBox[
       RowBox[{"compact", 
        StyleBox["X",
         FontSlant->"Italic"]}]]}], "\[Subset]", 
     SuperscriptBox[
      StyleBox["\[DoubleStruckCapitalR]",
       FontSize->14,
       FontSlant->"Italic"], 
      RowBox[{" ", "n"}]]}], "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"WaveletKernel", "[", 
      RowBox[{"x_", ",", "y_", ",", "a_"}], "]"}], "=", 
     RowBox[{
      RowBox[{"Cos", "[", 
       RowBox[{"1.75", " ", 
        FractionBox[
         RowBox[{"x", "-", "y"}], "a"]}], "]"}], " ", 
      SuperscriptBox["\[ExponentialE]", 
       RowBox[{"-", 
        FractionBox[
         SuperscriptBox[
          RowBox[{"(", 
           RowBox[{"x", "-", "y"}], ")"}], "2"], 
         RowBox[{"2", " ", 
          SuperscriptBox["a", "2"]}]]}]]}]}], ";"}], "\[IndentingNewLine]", 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"KernelMatrix", "[", 
      RowBox[{"K_", ",", "X_"}], "]"}], ":=", 
     RowBox[{"Outer", "[", 
      RowBox[{"K", ",", "X", ",", "X", ",", "1"}], "]"}]}], ";"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"KernelMatrix", "[", 
      RowBox[{"K_", ",", "X_", ",", "X1_"}], "]"}], ":=", 
     RowBox[{"Outer", "[", 
      RowBox[{"K", ",", "X", ",", "X1", ",", "1"}], "]"}]}], ";"}], 
   "\[IndentingNewLine]"}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->CompressedData["
1:eJxTTMoPSmViYGCQBGIQzdDwelqk5itHhobJCyF04A8IffovhC5yuwGiGVo9
IHS4L5humBoMoUtiIeJX4yD86N23wXyZw2C6QeYshH73FEJ7MP4C0xWsELpz
G4SeCqUv/IDQPr/BNENJ8G8w/T4UTDfMFfwDph3EIHSeNJhmCJGH0PVqEPFA
DQg9KRBCW0ZB6Dafv2Ca3xdMM+wIgdCHoHRhFITWiIaou1wH4ac2Q/h1cyB8
1bkQ/m1zNi0Q/RtCM9zzVQXTtoEQutxZByz/Ekq/CIHQZyIg9P58MM3woABE
AwAUx6kJ
  "]]
}, Closed]],

Cell[CellGroupData[{

Cell["implement of diff svm", "Subsection",
 CellChangeTimes->{{3.512029629078125*^9, 3.512029641484375*^9}, {
  3.51210397309375*^9, 3.51210397353125*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{"different", " ", 
    StyleBox["SVM",
     FontColor->RGBColor[0.5, 0, 0.5]]}], "*)"}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
    RowBox[{"the", " ", "classic", " ", "SVM"}], ",", " ", 
    RowBox[{"linear", " ", "separable"}], ",", 
    RowBox[{"C", "=", "\[Infinity]"}], ",", "\[IndentingNewLine]", 
    RowBox[{"can", " ", "it", " ", "be", " ", 
     RowBox[{"useful", "?"}]}]}], "*)"}], "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"oSVM", "[", 
      RowBox[{"X_", ",", "Y_", ",", "K_", ",", "opt___"}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
        "aa", ",", "ind", ",", "ind1", ",", "v", ",", "w", ",", "b", ",", 
         "svm"}], "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
         RowBox[{"get", " ", "alpha"}], ",", " ", 
         RowBox[{"linear", " ", "separable", " ", "so", " ", 
          RowBox[{"cs", "[", 
           RowBox[{"[", "2", "]"}], "]"}], " ", "is", " ", "\[Infinity]"}]}], 
        "*)"}], "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{"constrains", ":", " ", 
         RowBox[{
          RowBox[{"usually", " ", 
           RowBox[{"cs", "[", 
            RowBox[{"[", "1", "]"}], "]"}]}], "\[Equal]", "0"}]}], "*)"}], 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"aa", "=", 
         RowBox[{"QPSolve", "[", 
          RowBox[{"X", ",", "Y", ",", "K", ",", 
           RowBox[{"{", 
            RowBox[{"\[Infinity]", ",", "\[Infinity]"}], "}"}], ",", "opt"}], 
          "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "aa", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"ind1", "=", 
         RowBox[{"SVindex", "[", 
          RowBox[{"aa", ",", "Y"}], "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"ind", "=", 
         RowBox[{"Flatten", "[", 
          RowBox[{"Join", "[", "ind1", "]"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "\"\<get v \>\"", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"v", "=", 
         RowBox[{
          RowBox[{
          "aa", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}], "*", 
          RowBox[{
          "Y", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}]}], 
        ";", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
         "only", " ", "id", " ", "k", " ", "can", " ", "use", " ", "w", " ", 
          "directly"}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"K", "\[Equal]", "IdentityKernel"}], ",", 
          "\[IndentingNewLine]", 
          RowBox[{"w", "=", 
           RowBox[{"v", ".", 
            RowBox[{"X", "[", 
             RowBox[{"[", "ind", "]"}], "]"}]}]}]}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{
          "b", " ", "is", " ", "calc", " ", "from", " ", "all", " ", "data", 
           " ", "points"}], ",", " ", 
          RowBox[{"slow", ".."}]}], "*)"}], "\n", 
        RowBox[{"b", "=", " ", 
         RowBox[{
          FractionBox[
           RowBox[{"-", "1"}], "2"], "  ", 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"Mean", "[", 
             RowBox[{"v", ".", " ", 
              RowBox[{"KernelMatrix", "[", 
               RowBox[{"K", ",", 
                RowBox[{
                "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}],
                 ",", 
                RowBox[{"X", "\[LeftDoubleBracket]", 
                 RowBox[{"ind1", "[", 
                  RowBox[{"[", "1", "]"}], "]"}], "\[RightDoubleBracket]"}]}],
                "]"}]}], "]"}], "+", " ", 
            RowBox[{"Mean", "[", 
             RowBox[{"v", ".", 
              RowBox[{"KernelMatrix", "[", 
               RowBox[{"K", ",", 
                RowBox[{
                "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}],
                 ",", 
                RowBox[{"X", "\[LeftDoubleBracket]", 
                 RowBox[{"ind1", "[", 
                  RowBox[{"[", "2", "]"}], "]"}], "\[RightDoubleBracket]"}]}],
                "]"}]}], "]"}]}], ")"}]}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "b", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<offset\>\"", "]"}], "=", "b"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<alpha\>\"", "]"}], "=", "aa"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svi\>\"", "]"}], "=", "v"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svX\>\"", "]"}], "=", 
         RowBox[{
         "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}], ";",
         "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svY\>\"", "]"}], "=", 
         RowBox[{
         "Y", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}], ";",
         "\[IndentingNewLine]", "svm"}]}], "\[IndentingNewLine]", "]"}]}], 
    ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"cSVM", "[", 
      RowBox[{"X_", ",", "Y_", ",", "K_", ",", "opt___"}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
        "aa", ",", "ind", ",", "ind1", ",", "v", ",", "w", ",", "b", ",", 
         "svm", ",", "c"}], "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{"C", "-", 
         RowBox[{"SVM", ":", " ", 
          RowBox[{
           RowBox[{"cs", "[", 
            RowBox[{"[", "2", "]"}], "]"}], " ", "is", " ", "c"}]}]}], "*)"}],
        "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"c", "=", 
         RowBox[{"(", 
          RowBox[{
           RowBox[{"cost", "/.", 
            RowBox[{"{", "opt", "}"}]}], "/.", 
           RowBox[{"Options", "[", "SVMTrain", "]"}]}], ")"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{
           RowBox[{
            RowBox[{"c", "[", 
             RowBox[{"[", "1", "]"}], "]"}], "\[LessEqual]", "0"}], "\[Or]", 
           RowBox[{
            RowBox[{"c", "[", 
             RowBox[{"[", "2", "]"}], "]"}], "\[LessEqual]", "0"}]}], ",", 
          RowBox[{
           RowBox[{"Print", "[", "\"\<option cost error\>\"", "]"}], ";", 
           RowBox[{"Return", "[", "$Failed", "]"}], ";"}]}], "]"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{"constrains", ":", " ", 
          RowBox[{
           RowBox[{"usually", " ", 
            RowBox[{"cs", "[", 
             RowBox[{"[", "1", "]"}], "]"}]}], "\[Equal]", "0"}]}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"aa", "=", 
         RowBox[{"QPSolve", "[", 
          RowBox[{"X", ",", "Y", ",", "K", ",", "c", ",", "opt"}], "]"}]}], 
        ";", "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"aa", "\[Equal]", "$Failed"}], ",", 
          RowBox[{"Return", "[", "$Failed", "]"}]}], "]"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "aa", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"ind1", "=", 
         RowBox[{"SVindex", "[", 
          RowBox[{"aa", ",", "Y"}], "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"ind", "=", 
         RowBox[{"Flatten", "[", 
          RowBox[{"Join", "[", "ind1", "]"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "\"\<get v \>\"", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"v", "=", 
         RowBox[{
          RowBox[{
          "aa", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}], "*", 
          RowBox[{
          "Y", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}]}], 
        ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{
          "b", " ", "is", " ", "calc", " ", "from", " ", "all", " ", "data", 
           " ", "points"}], ",", " ", 
          RowBox[{"slow", ".."}]}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{"b", "=", " ", 
         RowBox[{
          FractionBox[
           RowBox[{"-", "1"}], "2"], "  ", 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"Mean", "[", 
             RowBox[{"v", ".", " ", 
              RowBox[{"KernelMatrix", "[", 
               RowBox[{"K", ",", 
                RowBox[{
                "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}],
                 ",", 
                RowBox[{"X", "\[LeftDoubleBracket]", 
                 RowBox[{"ind1", "[", 
                  RowBox[{"[", "1", "]"}], "]"}], "\[RightDoubleBracket]"}]}],
                "]"}]}], "]"}], "+", " ", 
            RowBox[{"Mean", "[", 
             RowBox[{"v", ".", 
              RowBox[{"KernelMatrix", "[", 
               RowBox[{"K", ",", 
                RowBox[{
                "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}],
                 ",", 
                RowBox[{"X", "\[LeftDoubleBracket]", 
                 RowBox[{"ind1", "[", 
                  RowBox[{"[", "2", "]"}], "]"}], "\[RightDoubleBracket]"}]}],
                "]"}]}], "]"}]}], ")"}]}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<offset\>\"", "]"}], "=", "b"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<alpha\>\"", "]"}], "=", "aa"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svi\>\"", "]"}], "=", "v"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svX\>\"", "]"}], "=", 
         RowBox[{
         "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}], ";",
         "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svY\>\"", "]"}], "=", 
         RowBox[{
         "Y", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}], ";",
         "\[IndentingNewLine]", "svm"}]}], "\[IndentingNewLine]", "]"}]}], 
    ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"nuSVM", "[", 
      RowBox[{"X_", ",", "Y_", ",", "K_", ",", "opt___"}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
        "aa", ",", "ind", ",", "ind1", ",", "v", ",", "w", ",", "b", ",", 
         "svm", ",", "n"}], "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"n", "=", 
         RowBox[{
          RowBox[{"nu", "/.", 
           RowBox[{"{", "opt", "}"}]}], "/.", 
          RowBox[{"Options", "[", "SVMTrain", "]"}]}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"aa", "=", 
         RowBox[{"QPSolve", "[", 
          RowBox[{"X", ",", "Y", ",", "K", ",", "n", ",", "opt"}], "]"}]}], 
        ";", "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"aa", "\[Equal]", "$Failed"}], ",", 
          RowBox[{"Return", "[", "$Failed", "]"}]}], "]"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "aa", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"ind1", "=", 
         RowBox[{"SVindex", "[", 
          RowBox[{"aa", ",", "Y"}], "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"ind", "=", 
         RowBox[{"Flatten", "[", 
          RowBox[{"Join", "[", "ind1", "]"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "\"\<get v \>\"", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"v", "=", 
         RowBox[{
          RowBox[{
          "aa", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}], "*", 
          RowBox[{
          "Y", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}]}], 
        ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{
          "b", " ", "is", " ", "calc", " ", "from", " ", "all", " ", "data", 
           " ", "points"}], ",", " ", 
          RowBox[{"slow", ".."}]}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{"b", "=", " ", 
         RowBox[{
          FractionBox[
           RowBox[{"-", "1"}], "2"], "  ", 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"Mean", "[", 
             RowBox[{"v", ".", " ", 
              RowBox[{"KernelMatrix", "[", 
               RowBox[{"K", ",", 
                RowBox[{
                "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}],
                 ",", 
                RowBox[{"X", "\[LeftDoubleBracket]", 
                 RowBox[{"ind1", "[", 
                  RowBox[{"[", "1", "]"}], "]"}], "\[RightDoubleBracket]"}]}],
                "]"}]}], "]"}], "+", " ", 
            RowBox[{"Mean", "[", 
             RowBox[{"v", ".", 
              RowBox[{"KernelMatrix", "[", 
               RowBox[{"K", ",", 
                RowBox[{
                "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}],
                 ",", 
                RowBox[{"X", "\[LeftDoubleBracket]", 
                 RowBox[{"ind1", "[", 
                  RowBox[{"[", "2", "]"}], "]"}], "\[RightDoubleBracket]"}]}],
                "]"}]}], "]"}]}], ")"}]}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<offset\>\"", "]"}], "=", "b"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<alpha\>\"", "]"}], "=", "aa"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svi\>\"", "]"}], "=", "v"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svX\>\"", "]"}], "=", 
         RowBox[{
         "X", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}], ";",
         "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"svm", "[", "\"\<svY\>\"", "]"}], "=", 
         RowBox[{
         "Y", "\[LeftDoubleBracket]", "ind", "\[RightDoubleBracket]"}]}], ";",
         "\[IndentingNewLine]", "svm"}]}], "\[IndentingNewLine]", "]"}]}], 
    ";"}], "\[IndentingNewLine]"}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.51159968415625*^9}, {3.51159972271875*^9, 3.511599772671875*^9}, {
   3.511599851640625*^9, 3.51159986265625*^9}, {3.511606746859375*^9, 
   3.511606808875*^9}, {3.511606888890625*^9, 3.511607087453125*^9}, {
   3.511668746265625*^9, 3.511668779765625*^9}, {3.511669289859375*^9, 
   3.511669365328125*^9}, {3.51167452465625*^9, 3.511674532765625*^9}, {
   3.51167541496875*^9, 3.51167542659375*^9}, 3.511676043890625*^9, {
   3.51167614634375*^9, 3.5116761631875*^9}, {3.511693586578125*^9, 
   3.511693586875*^9}, {3.511693678515625*^9, 3.511693680453125*^9}, {
   3.51169371796875*^9, 3.511693726453125*^9}, {3.511693768203125*^9, 
   3.511693781453125*^9}, {3.511694579578125*^9, 3.511694652671875*^9}, {
   3.511694749984375*^9, 3.511694856140625*^9}, {3.511695255890625*^9, 
   3.511695267125*^9}, {3.511695894671875*^9, 3.511695902953125*^9}, {
   3.511696375125*^9, 3.511696380078125*^9}, {3.5117514461875*^9, 
   3.51175147178125*^9}, 3.51175163803125*^9, 3.5117526550625*^9, {
   3.51175270690625*^9, 3.5117527083125*^9}, {3.5117527518125*^9, 
   3.511752769765625*^9}, {3.511752839875*^9, 3.511752865265625*^9}, {
   3.511753594890625*^9, 3.511753749859375*^9}, {3.51175448884375*^9, 
   3.511754503859375*^9}, {3.51175453934375*^9, 3.51175454496875*^9}, {
   3.5117548300625*^9, 3.511754844484375*^9}, {3.51175522675*^9, 
   3.5117552933125*^9}, {3.511755348703125*^9, 3.511755474625*^9}, {
   3.511755689328125*^9, 3.51175581484375*^9}, {3.51175585065625*^9, 
   3.51175594909375*^9}, {3.511756099875*^9, 3.51175616346875*^9}, {
   3.51175624140625*^9, 3.511756272953125*^9}, {3.511757410953125*^9, 
   3.511757412421875*^9}, {3.5117575035*^9, 3.511757556875*^9}, {
   3.51175769621875*^9, 3.511757778484375*^9}, {3.511757817921875*^9, 
   3.511757832578125*^9}, {3.511762665703125*^9, 3.51176270371875*^9}, {
   3.511762766890625*^9, 3.511762773953125*^9}, {3.511771014515625*^9, 
   3.51177105803125*^9}, {3.51177142225*^9, 3.511771439671875*^9}, {
   3.5117715235*^9, 3.511771542015625*^9}, {3.511771572765625*^9, 
   3.51177159984375*^9}, 3.511774414140625*^9, 3.511775736078125*^9, {
   3.511776001703125*^9, 3.511776003953125*^9}, {3.51177822303125*^9, 
   3.51177824128125*^9}, {3.511778278578125*^9, 3.511778284265625*^9}, {
   3.511778327984375*^9, 3.51177833*^9}, {3.511780360671875*^9, 
   3.511780468234375*^9}, {3.51178106346875*^9, 3.5117810678125*^9}, {
   3.511781315765625*^9, 3.511781316234375*^9}, {3.511781495015625*^9, 
   3.511781513265625*^9}, 3.511782268921875*^9, {3.511782310015625*^9, 
   3.511782314953125*^9}, 3.51178236384375*^9, {3.511782423328125*^9, 
   3.511782449640625*^9}, {3.511782489921875*^9, 3.51178257134375*^9}, {
   3.511782665796875*^9, 3.511782669140625*^9}, 3.511782941125*^9, {
   3.51178300865625*^9, 3.511783012015625*^9}, {3.511783329109375*^9, 
   3.511783343234375*^9}, {3.511783438265625*^9, 3.511783472*^9}, {
   3.51178400096875*^9, 3.511784007484375*^9}, {3.511784196984375*^9, 
   3.511784208375*^9}, {3.5117845628125*^9, 3.51178456340625*^9}, {
   3.51182465259375*^9, 3.5118246625*^9}, {3.51182495571875*^9, 
   3.51182506553125*^9}, {3.511825117390625*^9, 3.511825140015625*^9}, {
   3.511825239890625*^9, 3.511825246328125*^9}, 3.51182530165625*^9, {
   3.511825389921875*^9, 3.51182541928125*^9}, {3.511825530078125*^9, 
   3.511825534953125*^9}, 3.51182563071875*^9, {3.51182572521875*^9, 
   3.511825768984375*^9}, {3.511825844875*^9, 3.51182584653125*^9}, {
   3.511840902734375*^9, 3.511840932875*^9}, 3.5118421779375*^9, {
   3.511847924921875*^9, 3.511847933328125*^9}, {3.512029286828125*^9, 
   3.512029312*^9}, {3.512083545*^9, 3.51208354540625*^9}, {3.5120837495*^9, 
   3.51208374978125*^9}, {3.5121882345*^9, 3.512188240609375*^9}, {
   3.51218831428125*^9, 3.5121883425625*^9}, {3.512188484234375*^9, 
   3.51218849546875*^9}, 3.512188625125*^9, {3.512189560296875*^9, 
   3.512189741328125*^9}, {3.512189786671875*^9, 3.512189790703125*^9}, {
   3.51219006625*^9, 3.51219011175*^9}, {3.512192879171875*^9, 
   3.5121928835*^9}, {3.512192979234375*^9, 3.51219300665625*^9}, 
   3.512194379015625*^9, {3.51229198659375*^9, 3.512292024921875*^9}, {
   3.512293887015625*^9, 3.5122938886875*^9}, {3.51229454053125*^9, 
   3.5122945608125*^9}, {3.5122948955625*^9, 3.512294896984375*^9}, {
   3.512294947765625*^9, 3.512295003921875*^9}, {3.512295519140625*^9, 
   3.512295545078125*^9}}]
}, Open  ]],

Cell[CellGroupData[{

Cell["support routines", "Subsection",
 CellChangeTimes->{{3.51202965496875*^9, 3.51202966625*^9}}],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"SVindex", "[", "\[Alpha]_List", "]"}], ":=", "\n", "  ", 
    RowBox[{"Flatten", "[", 
     RowBox[{"Position", "[", 
      RowBox[{"\[Alpha]", ",", 
       RowBox[{"a_", "/;", 
        RowBox[{"a", "!=", "0"}]}]}], "]"}], "]"}]}], ";"}], 
  "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
    RowBox[{"this", " ", "find"}], " ", "+", 
    RowBox[{"1", " ", "and"}], " ", "-", 
    RowBox[{"1", " ", "sv", " ", "respectively"}]}], 
   "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"SVindex", "[", 
     RowBox[{"\[Alpha]_List", ",", "   ", "y_List"}], "]"}], ":=", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{
       RowBox[{"Position", "[", 
        RowBox[{
         RowBox[{"\[Alpha]", "*", "y"}], ",", 
         RowBox[{"_", "?", "Positive"}]}], "]"}], "//", "Flatten"}], ",", 
      "\n", "    ", 
      RowBox[{
       RowBox[{"Position", "[", 
        RowBox[{
         RowBox[{"\[Alpha]", "*", "y"}], ",", 
         RowBox[{"_", "?", "Negative"}]}], "]"}], "//", "Flatten"}]}], 
     "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
    RowBox[{
     RowBox[{"WeightVector", "[", 
      RowBox[{"\[Alpha]_List", ",", 
       RowBox[{"X_", "?", "MatrixQ"}], ",", "y_List"}], "]"}], ":=", "\n", 
     "  ", 
     RowBox[{"Sum", "[", 
      RowBox[{
       RowBox[{
        RowBox[{"y", "[", 
         RowBox[{"[", "i", "]"}], "]"}], "*", 
        RowBox[{"\[Alpha]", "[", 
         RowBox[{"[", " ", "i", "]"}], "]"}], "*", 
        RowBox[{"X", "[", 
         RowBox[{"[", "i", "]"}], "]"}]}], ",", 
       RowBox[{"{", 
        RowBox[{"i", ",", " ", 
         RowBox[{"Length", "[", "X", "]"}]}], "}"}]}], "]"}]}], ";"}], "*)"}],
   "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
    RowBox[{
     RowBox[{"Bias", "[", 
      RowBox[{"\[Alpha]_", ",", "X_", ",", "Y_", ",", "K_"}], "]"}], ":=", 
     "\n", "  ", 
     RowBox[{"Module", "[", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"sv", ",", "ind", ",", "v"}], "}"}], ",", "\n", " ", 
       RowBox[{
        RowBox[{"ind", "=", 
         RowBox[{"SVindex", "[", 
          RowBox[{"\[Alpha]", ",", "Y"}], "]"}]}], ";", "\n", "      ", 
        RowBox[{
         FractionBox[
          RowBox[{"-", "1"}], "2"], 
         RowBox[{"v", ".", " ", 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"KernelMatrix", "[", 
             RowBox[{"K", ",", "X", ",", 
              RowBox[{"X", "\[LeftDoubleBracket]", 
               RowBox[{"ind1", "[", 
                RowBox[{"[", "1", "]"}], "]"}], "\[RightDoubleBracket]"}]}], 
             "]"}], "+", " ", 
            RowBox[{"KernelMatrix", "[", 
             RowBox[{"K", ",", "X", ",", 
              RowBox[{"X", "\[LeftDoubleBracket]", 
               RowBox[{"ind1", "[", 
                RowBox[{"[", "2", "]"}], "]"}], "\[RightDoubleBracket]"}]}], 
             "]"}]}], ")"}]}]}]}]}], "\[IndentingNewLine]", "]"}]}], ";"}], 
   "*)"}]}]}], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.51159968415625*^9}, {3.51159972271875*^9, 3.511599772671875*^9}, {
   3.511599851640625*^9, 3.51159986265625*^9}, {3.511606746859375*^9, 
   3.511606808875*^9}, {3.511606888890625*^9, 3.511607087453125*^9}, {
   3.511668746265625*^9, 3.511668779765625*^9}, {3.511669289859375*^9, 
   3.511669365328125*^9}, {3.51167452465625*^9, 3.511674532765625*^9}, {
   3.51167541496875*^9, 3.51167542659375*^9}, 3.511676043890625*^9, {
   3.51167614634375*^9, 3.5116761631875*^9}, {3.511693586578125*^9, 
   3.511693586875*^9}, {3.511693678515625*^9, 3.511693680453125*^9}, {
   3.51169371796875*^9, 3.511693726453125*^9}, {3.511693768203125*^9, 
   3.511693781453125*^9}, {3.511694579578125*^9, 3.511694652671875*^9}, {
   3.511694749984375*^9, 3.511694856140625*^9}, {3.511695255890625*^9, 
   3.511695267125*^9}, {3.511695894671875*^9, 3.511695902953125*^9}, {
   3.511696375125*^9, 3.51169638628125*^9}, 3.511740094734375*^9, {
   3.51175286725*^9, 3.51175288303125*^9}, {3.51175300184375*^9, 
   3.51175300328125*^9}, {3.5117540255625*^9, 3.511754046484375*^9}, {
   3.51175414965625*^9, 3.511754195453125*^9}, {3.511754265453125*^9, 
   3.511754299359375*^9}, {3.51175442559375*^9, 3.51175446946875*^9}, {
   3.511757939265625*^9, 3.5117579845625*^9}, 3.511774025484375*^9, {
   3.5117743183125*^9, 3.511774332578125*^9}, {3.51178147546875*^9, 
   3.511781477296875*^9}}]
}, Closed]],

Cell[CellGroupData[{

Cell["QPsolve algorithms", "Subsection",
 CellChangeTimes->{{3.5120296840625*^9, 3.512029701453125*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
    RowBox[{"this", " ", "is", " ", "a", " ", "wrapper", " ", "function"}], 
    ",", "\[IndentingNewLine]", 
    RowBox[{"K", " ", "is", " ", "kernel"}], ",", " ", 
    RowBox[{"Cs", " ", "is", " ", "constrain", 
     RowBox[{"(", 
      RowBox[{
       RowBox[{
        RowBox[{"corresponding", " ", "to", " ", 
         RowBox[{"cost", " ", "[", 
          RowBox[{"Cp", ",", "Cn"}], "]"}]}], ";", " ", 
        RowBox[{
         RowBox[{"Cs", " ", "always"}], " ", "\[GreaterEqual]", "0"}]}], ",", 
       " ", 
       RowBox[{"so", " ", "this", " ", "is", " ", "omitted"}]}], ")"}]}], ",",
     " ", 
    RowBox[{
    "method", " ", "is", " ", "the", " ", "option", " ", "for", " ", 
     "QPsolve", " ", "algorithm"}], ",", " ", 
    RowBox[{
    "return", " ", "$Failed", " ", "when", " ", "error", " ", "occurred"}]}], 
   "*)"}], "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"QPSolve", "[", 
      RowBox[{"X_", ",", "Y_", ",", "K_", ",", "Cs_", ",", "opt___"}], "]"}], 
     ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"g", ",", "KM", ",", "\[Tau]"}], "}"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
         RowBox[{"Print", "[", "\"\<enter QPSolve\>\"", "]"}], ";"}], "*)"}], 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"\[Tau]", "=", 
         RowBox[{
          RowBox[{"t", "/.", 
           RowBox[{"{", "opt", "}"}]}], "/.", 
          RowBox[{"Options", "[", "SVMTrain", "]"}]}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"If", "[", 
           RowBox[{
            RowBox[{"0", "\[LessEqual]", "\[Tau]", "\[LessEqual]", "1"}], ",",
             ",", 
            RowBox[{
             RowBox[{"Return", "[", "]"}], ";"}]}], "]"}], ";"}], 
         "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", 
        RowBox[{"KM", "=", 
         RowBox[{"KernelMatrix", "[", 
          RowBox[{"K", ",", "X"}], "]"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"Switch", "[", 
         RowBox[{
          RowBox[{
           RowBox[{"qpType", "/.", 
            RowBox[{"{", "opt", "}"}]}], "/.", 
           RowBox[{"Options", "[", "SVMTrain", "]"}]}], ",", 
          "\[IndentingNewLine]", "1", ",", 
          RowBox[{"(*", 
           RowBox[{"classic", " ", "method"}], "*)"}], "\[IndentingNewLine]", 
          RowBox[{"QPsolves", "[", 
           RowBox[{
            RowBox[{"KM", "*", 
             RowBox[{"Outer", "[", 
              RowBox[{"Times", ",", "Y", ",", "Y"}], "]"}]}], ",", "Y", ",", 
            "\[Tau]", ",", "Cs"}], "]"}], ",", "\[IndentingNewLine]", "2", 
          ",", 
          RowBox[{"(*", 
           RowBox[{"SMO", " ", "in", " ", "dlib"}], "*)"}], 
          "\[IndentingNewLine]", 
          RowBox[{"QPsolvedlib", "[", 
           RowBox[{
            RowBox[{"KM", "*", 
             RowBox[{"Outer", "[", 
              RowBox[{"Times", ",", "Y", ",", "Y"}], "]"}]}], ",", "Y", ",", 
            "\[Tau]", ",", "Cs"}], "]"}], ",", "\[IndentingNewLine]", "3", 
          ",", 
          RowBox[{"(*", 
           RowBox[{
            RowBox[{"special", " ", "for", " ", "nu"}], "-", "SVM"}], "*)"}], 
          "\[IndentingNewLine]", 
          RowBox[{"QPsolvedlib2", "[", 
           RowBox[{
            RowBox[{"KM", "*", 
             RowBox[{"Outer", "[", 
              RowBox[{"Times", ",", "Y", ",", "Y"}], "]"}]}], ",", "Y", ",", 
            "\[Tau]", ",", "Cs"}], "]"}], ",", "\[IndentingNewLine]", "_", 
          ",", 
          RowBox[{
           RowBox[{"Print", "[", "\"\<qpType error.\>\"", "]"}], ";", 
           "$Failed"}]}], "\[IndentingNewLine]", "]"}]}]}], 
      "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{"Quadratic", " ", "problem", " ", "solution", " ", 
      RowBox[{"here", ".", " ", "Pure"}], " ", "Qp", "\[IndentingNewLine]", 
      RowBox[{"Cs", ":", " ", 
       RowBox[{"only", " ", "Cp", " ", "used", " ", "here"}]}]}], ",", 
     "\[IndentingNewLine]", " ", 
     RowBox[{
     "input", " ", "Q", " ", "must", " ", "be", " ", "a", " ", "positive", 
      " ", "semidefinite", " ", "matrix"}], ",", " ", 
     RowBox[{"return", " ", "\[Alpha]"}]}], " ", "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"classical", " ", "method"}], "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"QPsolves", "[", 
      RowBox[{"Q_", ",", "Y_", ",", "\[Tau]_", ",", "cs_"}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
        "m", ",", "i", ",", "j", ",", "W", ",", "g", ",", "vars", ",", "sol", 
         ",", "p"}], "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"m", "=", 
         RowBox[{"Length", "[", "Y", "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"(*", "precision", "*)"}], "\[IndentingNewLine]", 
        RowBox[{"p", "=", 
         RowBox[{"Ceiling", "[", 
          RowBox[{"-", 
           RowBox[{"Log", "[", 
            RowBox[{"10", ",", "\[Tau]"}], "]"}]}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"p", "\[LessEqual]", "0"}], ",", 
          RowBox[{
           RowBox[{"Print", "[", "\"\<\[Tau] error in QPsolves\>\"", "]"}], 
           ";", 
           RowBox[{"Return", "[", "]"}]}]}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"vars", "=", 
         RowBox[{"Table", "[", 
          RowBox[{
           SubscriptBox["\[Alpha]", "i"], ",", 
           RowBox[{"{", 
            RowBox[{"i", ",", "1", ",", "m"}], "}"}]}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"W", "=", 
           RowBox[{
            RowBox[{
             UnderoverscriptBox["\[Sum]", 
              RowBox[{"i", "=", "1"}], "m"], 
             SubscriptBox["\[Alpha]", "i"]}], "-", 
            RowBox[{
             FractionBox["1", "2"], 
             RowBox[{
              UnderoverscriptBox["\[Sum]", 
               RowBox[{"i", "=", "1"}], "m"], 
              RowBox[{
               UnderoverscriptBox["\[Sum]", 
                RowBox[{"j", "=", "1"}], "m"], 
               RowBox[{"(", 
                RowBox[{
                 RowBox[{"Y", "[", 
                  RowBox[{"[", "i", "]"}], "]"}], " ", 
                 RowBox[{"Y", "[", 
                  RowBox[{"[", "j", "]"}], "]"}], " ", 
                 SubscriptBox["\[Alpha]", "i"], 
                 SubscriptBox["\[Alpha]", "j"], " ", 
                 RowBox[{"KM", "[", 
                  RowBox[{"[", 
                   RowBox[{"i", ",", "j"}], "]"}], "]"}]}], ")"}]}]}]}]}]}], 
          ";"}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{"W", "=", 
         RowBox[{
          RowBox[{
           UnderoverscriptBox["\[Sum]", 
            RowBox[{"i", "=", "1"}], "m"], 
           SubscriptBox["\[Alpha]", "i"]}], " ", "-", 
          RowBox[{
           FractionBox["1", "2"], 
           RowBox[{"vars", ".", "Q", ".", "vars"}]}]}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"g", "=", 
         RowBox[{"Apply", "[", 
          RowBox[{"And", ",", 
           RowBox[{"Join", "[", 
            RowBox[{
             RowBox[{"Table", "[", 
              RowBox[{
               RowBox[{
                RowBox[{
                "cs", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], 
                "\[GreaterEqual]", " ", 
                SubscriptBox["\[Alpha]", "i"], "\[GreaterEqual]", "0"}], ",", 
               RowBox[{"{", 
                RowBox[{"i", ",", "1", ",", "m"}], "}"}]}], "]"}], ",", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{
                UnderoverscriptBox["\[Sum]", 
                 RowBox[{"i", "=", "1"}], "m"], 
                RowBox[{
                 RowBox[{"Y", "[", 
                  RowBox[{"[", "i", "]"}], "]"}], " ", 
                 SubscriptBox["\[Alpha]", "i"]}]}], "\[Equal]", "0"}], 
              "}"}]}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"sol", "=", 
         RowBox[{
          RowBox[{"NMaximize", "[", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{"W", ",", "g"}], "}"}], ",", "vars", ",", 
            RowBox[{"Method", "\[Rule]", "\"\<DifferentialEvolution\>\""}], 
            ",", 
            RowBox[{"AccuracyGoal", "\[Rule]", "p"}]}], "]"}], "[", 
          RowBox[{"[", "2", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"m", "=", 
           RowBox[{"Max", "[", 
            RowBox[{"vars", "/.", "sol"}], "]"}]}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
         "choose", " ", "only", " ", "big", " ", "enough", " ", "elements"}], 
         "*)"}], "\[IndentingNewLine]", 
        RowBox[{"Chop", "[", 
         RowBox[{
          RowBox[{"vars", "/.", "sol"}], ",", "\[Tau]"}], "]"}]}]}], 
      "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{
     "this", " ", "func", " ", "link", " ", "to", " ", "the", " ", "Dlib", 
      " ", "lib"}], ",", " ", 
     RowBox[{"since", " ", "it", " ", "is", " ", "fast"}], ",", 
     RowBox[{
     "\[Tau]", " ", "can", " ", "be", " ", "0.0001", " ", "or", " ", 
      "smaller"}]}], " ", "*)"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"link", ";"}], "*)"}], "\[IndentingNewLine]", " ", 
   RowBox[{
    RowBox[{
     RowBox[{"QPsolvedlib", "[", 
      RowBox[{"Q_", ",", "Y_", ",", "\[Tau]_", ",", "cs_"}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"sol", ",", "c", ",", "link"}], "}"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"!", 
           RowBox[{"ValueQ", "[", 
            RowBox[{"QPsolveC", "::", "usage"}], "]"}]}], ",", 
          "\[IndentingNewLine]", 
          RowBox[{"link", "=", 
           RowBox[{"Install", "[", "\"\<out`\>\"", "]"}]}]}], "]"}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{
           RowBox[{"cs", "'"}], "s", " ", "lowb", " ", "is", " ", "not", " ", 
           "used"}], ",", " ", 
          RowBox[{"def", " ", "0", " ", "here"}], ","}], " ", "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{"will", " ", 
          RowBox[{"2", "^", "32"}], " ", "big", " ", "enough", "??"}], "*)"}],
         "\[IndentingNewLine]", 
        RowBox[{"c", "=", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"cs", "[", 
               RowBox[{"[", "1", "]"}], "]"}], "\[Equal]", "\[Infinity]"}], 
             ",", 
             RowBox[{"N", "[", 
              RowBox[{"10", "^", "10"}], "]"}], ",", 
             RowBox[{"N", "[", 
              RowBox[{
              "cs", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], 
              "]"}]}], "]"}], ",", 
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"cs", "[", 
               RowBox[{"[", "2", "]"}], "]"}], "\[Equal]", "\[Infinity]"}], 
             ",", 
             RowBox[{"N", "[", 
              RowBox[{"10", "^", "10"}], "]"}], ",", 
             RowBox[{"N", "[", 
              RowBox[{
              "cs", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], 
              "]"}]}], "]"}]}], "}"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "c", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"QPsolved", " ", "first", " ", "appears", " ", "here"}], 
          ",", " ", 
          RowBox[{
          "so", " ", "it", " ", "has", " ", "context", " ", "of", " ", 
           "`PP`"}]}], "*)"}], "\[IndentingNewLine]", 
        RowBox[{"sol", "=", 
         RowBox[{"QPsolveC", "[", 
          RowBox[{"\[Tau]", ",", 
           RowBox[{
           "c", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", 
           RowBox[{
           "c", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", 
           RowBox[{"N", "[", "Y", "]"}], ",", "Q"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Uninstall", "[", "link", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"Chop", "[", 
         RowBox[{"sol", ",", "\[Tau]"}], "]"}]}]}], "\[IndentingNewLine]", 
      "]"}]}], ";"}], "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
     RowBox[{
      RowBox[{"this", " ", "is", " ", "for", " ", "nu"}], "-", "SVM"}], ",", 
     RowBox[{"cs", " ", "has", " ", "the", " ", "nu"}]}], "*)"}], 
   "\[IndentingNewLine]", " ", 
   RowBox[{
    RowBox[{
     RowBox[{"QPsolvedlib2", "[", 
      RowBox[{"Q_", ",", "Y_", ",", "\[Tau]_", ",", "nu_"}], "]"}], ":=", 
     RowBox[{"Module", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"sol", ",", "c", ",", "link"}], "}"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"!", 
           RowBox[{"ValueQ", "[", 
            RowBox[{"QPsolveN", "::", "usage"}], "]"}]}], ",", 
          "\[IndentingNewLine]", 
          RowBox[{"link", "=", 
           RowBox[{"Install", "[", "\"\<out`\>\"", "]"}]}]}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", "c", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"sol", "=", 
         RowBox[{"QPsolveN", "[", 
          RowBox[{"\[Tau]", ",", "nu", ",", 
           RowBox[{"N", "[", "Y", "]"}], ",", "Q"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Uninstall", "[", "link", "]"}], ";"}], "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"Print", "[", 
           RowBox[{"sol", ",", 
            RowBox[{"Options", "[", "SVMTrain", "]"}]}], "]"}], ";"}], "*)"}],
         "\[IndentingNewLine]", 
        RowBox[{"Chop", "[", 
         RowBox[{"sol", ",", "\[Tau]"}], "]"}]}]}], "\[IndentingNewLine]", 
      "]"}]}], ";"}]}]}]], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.511340300609375*^9}, {
   3.511340994546875*^9, 3.511341038359375*^9}, {3.511599667578125*^9, 
   3.51159968415625*^9}, {3.51159972271875*^9, 3.511599772671875*^9}, {
   3.511599851640625*^9, 3.51159986265625*^9}, {3.511606746859375*^9, 
   3.511606808875*^9}, {3.511606888890625*^9, 3.511607087453125*^9}, {
   3.511668746265625*^9, 3.511668779765625*^9}, {3.511669289859375*^9, 
   3.511669365328125*^9}, {3.51167452465625*^9, 3.511674532765625*^9}, {
   3.51167541496875*^9, 3.51167542659375*^9}, {3.511676043890625*^9, 
   3.511676059828125*^9}, 3.51167609721875*^9, 3.51167930103125*^9, {
   3.51167936128125*^9, 3.5116793949375*^9}, {3.51168033209375*^9, 
   3.51168033890625*^9}, {3.511680390046875*^9, 3.51168044284375*^9}, {
   3.5116804943125*^9, 3.511680496625*^9}, {3.511680561203125*^9, 
   3.51168056171875*^9}, {3.511682042140625*^9, 3.51168205034375*^9}, {
   3.51168217428125*^9, 3.511682211*^9}, {3.5116828316875*^9, 
   3.511682836484375*^9}, {3.511682869921875*^9, 3.511682946421875*^9}, {
   3.511683130890625*^9, 3.511683231875*^9}, {3.5116842394375*^9, 
   3.51168428353125*^9}, {3.511684317546875*^9, 3.51168441003125*^9}, {
   3.5116844995*^9, 3.511684509453125*^9}, {3.51168473875*^9, 
   3.51168478203125*^9}, {3.511687067*^9, 3.511687123921875*^9}, {
   3.51168719025*^9, 3.51168719065625*^9}, {3.51168724090625*^9, 
   3.511687311171875*^9}, {3.511687395828125*^9, 3.511687418578125*^9}, {
   3.511687450796875*^9, 3.511687450953125*^9}, {3.511693930625*^9, 
   3.511693935078125*^9}, {3.51169404090625*^9, 3.511694079421875*^9}, {
   3.511695226*^9, 3.5116952341875*^9}, {3.51169527671875*^9, 
   3.511695302140625*^9}, {3.5116968605*^9, 3.511696884828125*^9}, 
   3.511736975609375*^9, {3.511737010296875*^9, 3.511737204328125*^9}, {
   3.511737615375*^9, 3.51173771503125*^9}, {3.5117377456875*^9, 
   3.5117379915625*^9}, {3.511738165171875*^9, 3.511738172*^9}, {
   3.511738216578125*^9, 3.5117382325*^9}, {3.51173830234375*^9, 
   3.511738423015625*^9}, {3.511738456984375*^9, 3.511738491015625*^9}, {
   3.5117387098125*^9, 3.511738784734375*^9}, {3.511738878859375*^9, 
   3.5117388966875*^9}, {3.511738928546875*^9, 3.51173894996875*^9}, {
   3.511738983859375*^9, 3.511739031859375*^9}, {3.51173963365625*^9, 
   3.511739766359375*^9}, {3.5117397993125*^9, 3.51173980978125*^9}, {
   3.511739849359375*^9, 3.5117399190625*^9}, {3.51174006996875*^9, 
   3.511740070046875*^9}, {3.51174033909375*^9, 3.511740348234375*^9}, {
   3.511740528*^9, 3.51174054609375*^9}, {3.51175153553125*^9, 
   3.511751668921875*^9}, 3.511752271015625*^9, {3.511752641875*^9, 
   3.511752646734375*^9}, {3.51175492659375*^9, 3.511754938140625*^9}, {
   3.511774267609375*^9, 3.51177428390625*^9}, 3.5117744974375*^9, {
   3.511775711125*^9, 3.511775712078125*^9}, {3.511775808359375*^9, 
   3.511775817921875*^9}, {3.511775912984375*^9, 3.51177591375*^9}, {
   3.51177595521875*^9, 3.51177596484375*^9}, {3.5117783384375*^9, 
   3.511778405484375*^9}, 3.511778702828125*^9, {3.51178132928125*^9, 
   3.511781339203125*^9}, {3.511781376984375*^9, 3.51178137740625*^9}, {
   3.511782330671875*^9, 3.511782342328125*^9}, 3.511842198875*^9, {
   3.51184296859375*^9, 3.51184299125*^9}, {3.5118436816875*^9, 
   3.511843718140625*^9}, {3.51192688665625*^9, 3.511926983328125*^9}, {
   3.5119270285625*^9, 3.5119270354375*^9}, {3.5119511553125*^9, 
   3.511951282109375*^9}, {3.512014595109375*^9, 3.512014642171875*^9}, {
   3.512014748921875*^9, 3.5120147615625*^9}, {3.5120148184375*^9, 
   3.512014877578125*^9}, {3.512014916046875*^9, 3.51201506109375*^9}, {
   3.51201510525*^9, 3.5120151073125*^9}, 3.512015225765625*^9, {
   3.5120153318125*^9, 3.512015386859375*^9}, {3.51201883675*^9, 
   3.51201883984375*^9}, {3.51201888609375*^9, 3.512018890578125*^9}, {
   3.51201952284375*^9, 3.512019547921875*^9}, {3.512021063046875*^9, 
   3.512021073265625*^9}, 3.512021326625*^9, 3.512021371765625*^9, {
   3.512021503984375*^9, 3.512021507390625*^9}, {3.512021685125*^9, 
   3.512021722765625*^9}, {3.51202185021875*^9, 3.512021852765625*^9}, {
   3.512021884828125*^9, 3.51202189978125*^9}, {3.512028466875*^9, 
   3.51202847165625*^9}, {3.51203124975*^9, 3.512031250828125*^9}, {
   3.51203171078125*^9, 3.51203173365625*^9}, {3.512031851421875*^9, 
   3.512031879328125*^9}, {3.51203462553125*^9, 3.512034633015625*^9}, {
   3.512034663640625*^9, 3.51203469528125*^9}, {3.512034995421875*^9, 
   3.51203502325*^9}, {3.51203507765625*^9, 3.512035080703125*^9}, {
   3.5120351145*^9, 3.512035129109375*^9}, {3.512036983421875*^9, 
   3.512036992125*^9}, {3.51219275009375*^9, 3.51219277559375*^9}, {
   3.512192809015625*^9, 3.5121928525*^9}, {3.512193052046875*^9, 
   3.512193118484375*^9}, {3.51219321921875*^9, 3.512193310921875*^9}, {
   3.512292055515625*^9, 3.512292070140625*^9}, {3.5122941033125*^9, 
   3.5122941040625*^9}, {3.512294141859375*^9, 3.512294169765625*^9}, {
   3.512294203890625*^9, 3.512294204921875*^9}, 3.512294379296875*^9, {
   3.5122946024375*^9, 3.512294626046875*^9}, {3.51229468284375*^9, 
   3.51229469471875*^9}, {3.512294768703125*^9, 3.51229486115625*^9}, {
   3.5122952139375*^9, 3.5122952211875*^9}, {3.512295329375*^9, 
   3.512295330703125*^9}, 3.5122953609375*^9, 3.51229563890625*^9}],

Cell[BoxData[{
 RowBox[{
  RowBox[{"End", "[", "]"}], ";"}], "\n", 
 RowBox[{
  RowBox[{"EndPackage", "[", "]"}], ";"}]}], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.511340215359375*^9, 3.5113402990625*^9}}]
}, Open  ]]
}, Open  ]],

Cell[CellGroupData[{

Cell["test here", "Subsubtitle",
 CellChangeTimes->{{3.511736936171875*^9, 3.511736938671875*^9}, {
  3.511740039078125*^9, 3.511740044125*^9}, {3.512031161015625*^9, 
  3.512031162390625*^9}}],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"m", "=", "4"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"KM", "=", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"i", ",", 
       RowBox[{"i", "+", "1"}], ",", 
       RowBox[{"i", "+", "2"}], ",", 
       RowBox[{"i", "+", "3"}]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{"i", ",", "m"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Y", "=", 
   RowBox[{"Table", "[", 
    RowBox[{"i", ",", 
     RowBox[{"{", 
      RowBox[{"i", ",", "m"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{"W", "=", 
  RowBox[{
   RowBox[{
    UnderoverscriptBox["\[Sum]", 
     RowBox[{"i", "=", "1"}], "m"], 
    SubscriptBox["\[Alpha]", "i"]}], "-", 
   RowBox[{
    FractionBox["1", "2"], 
    RowBox[{
     UnderoverscriptBox["\[Sum]", 
      RowBox[{"i", "=", "1"}], "m"], 
     RowBox[{
      UnderoverscriptBox["\[Sum]", 
       RowBox[{"j", "=", "1"}], "m"], 
      RowBox[{"(", 
       RowBox[{
        RowBox[{"Y", "[", 
         RowBox[{"[", "i", "]"}], "]"}], " ", 
        RowBox[{"Y", "[", 
         RowBox[{"[", "j", "]"}], "]"}], " ", 
        SubscriptBox["\[Alpha]", "i"], 
        SubscriptBox["\[Alpha]", "j"], " ", 
        RowBox[{"KM", "[", 
         RowBox[{"[", 
          RowBox[{"i", ",", "j"}], "]"}], "]"}]}], ")"}]}]}]}]}]}]}], "Input",
 CellChangeTimes->{{3.51173722315625*^9, 3.51173724390625*^9}, {
  3.511737305421875*^9, 3.51173739753125*^9}, {3.511738539640625*^9, 
  3.511738562109375*^9}}],

Cell[BoxData[
 RowBox[{
  SubscriptBox["\[Alpha]", "1"], "+", 
  SubscriptBox["\[Alpha]", "2"], "+", 
  SubscriptBox["\[Alpha]", "3"], "+", 
  SubscriptBox["\[Alpha]", "4"], "+", 
  RowBox[{
   FractionBox["1", "2"], " ", 
   RowBox[{"(", 
    RowBox[{
     RowBox[{"-", 
      SubsuperscriptBox["\[Alpha]", "1", "2"]}], "-", 
     RowBox[{"8", " ", 
      SubscriptBox["\[Alpha]", "1"], " ", 
      SubscriptBox["\[Alpha]", "2"]}], "-", 
     RowBox[{"12", " ", 
      SubsuperscriptBox["\[Alpha]", "2", "2"]}], "-", 
     RowBox[{"18", " ", 
      SubscriptBox["\[Alpha]", "1"], " ", 
      SubscriptBox["\[Alpha]", "3"]}], "-", 
     RowBox[{"48", " ", 
      SubscriptBox["\[Alpha]", "2"], " ", 
      SubscriptBox["\[Alpha]", "3"]}], "-", 
     RowBox[{"45", " ", 
      SubsuperscriptBox["\[Alpha]", "3", "2"]}], "-", 
     RowBox[{"32", " ", 
      SubscriptBox["\[Alpha]", "1"], " ", 
      SubscriptBox["\[Alpha]", "4"]}], "-", 
     RowBox[{"80", " ", 
      SubscriptBox["\[Alpha]", "2"], " ", 
      SubscriptBox["\[Alpha]", "4"]}], "-", 
     RowBox[{"144", " ", 
      SubscriptBox["\[Alpha]", "3"], " ", 
      SubscriptBox["\[Alpha]", "4"]}], "-", 
     RowBox[{"112", " ", 
      SubsuperscriptBox["\[Alpha]", "4", "2"]}]}], ")"}]}]}]], "Output",
 CellChangeTimes->{
  3.511737247859375*^9, 3.511737406546875*^9, {3.51173854890625*^9, 
   3.51173856340625*^9}}]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"Q", "=", 
  RowBox[{"KM", "*", 
   RowBox[{"Outer", "[", 
    RowBox[{"Times", ",", "Y", ",", "Y"}], "]"}]}]}]], "Input",
 CellChangeTimes->{{3.511737283140625*^9, 3.511737283421875*^9}, {
  3.511737416109375*^9, 3.511737421046875*^9}, {3.511737529171875*^9, 
  3.511737544578125*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
   RowBox[{"{", 
    RowBox[{"1", ",", "4", ",", "9", ",", "16"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"4", ",", "12", ",", "24", ",", "40"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"9", ",", "24", ",", "45", ",", "72"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"16", ",", "40", ",", "72", ",", "112"}], "}"}]}], 
  "}"}]], "Output",
 CellChangeTimes->{3.511737425671875*^9, 3.511737545453125*^9, 
  3.511738568359375*^9}]
}, Open  ]],

Cell[BoxData[
 RowBox[{
  RowBox[{"vars", "=", 
   RowBox[{"Table", "[", 
    RowBox[{
     SubscriptBox["\[Alpha]", "i"], ",", 
     RowBox[{"{", 
      RowBox[{"i", ",", "1", ",", "m"}], "}"}]}], "]"}]}], ";"}]], "Input"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"Expand", "[", 
  RowBox[{
   RowBox[{
    UnderoverscriptBox["\[Sum]", 
     RowBox[{"i", "=", "1"}], "m"], 
    SubscriptBox["\[Alpha]", "i"]}], " ", "-", 
   RowBox[{
    FractionBox["1", "2"], 
    RowBox[{"vars", ".", "Q", ".", "vars"}]}], "-", "W"}], "]"}]], "Input",
 CellChangeTimes->{{3.51173755625*^9, 3.511737575625*^9}, 
   3.511738506984375*^9, {3.5117385780625*^9, 3.511738638421875*^9}}],

Cell[BoxData["0"], "Output",
 CellChangeTimes->{{3.51173862921875*^9, 3.511738638890625*^9}}]
}, Open  ]],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"SupportVectors", "[", "\[Alpha]_List", "]"}], ":=", "\n", "  ", 
   RowBox[{"Flatten", "[", 
    RowBox[{"Position", "[", 
     RowBox[{"\[Alpha]", ",", 
      RowBox[{"a_", "/;", 
       RowBox[{"a", "\[NotEqual]", " ", "0"}]}]}], "]"}], "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.511753358890625*^9, 3.5117533888125*^9}, {
  3.51175351578125*^9, 3.511753568234375*^9}}],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"a", "=", 
  RowBox[{"Table", "[", 
   RowBox[{
    RowBox[{"RandomInteger", "[", "2", "]"}], ",", 
    RowBox[{"{", "50", "}"}]}], "]"}]}]], "Input",
 CellChangeTimes->{{3.5117529390625*^9, 3.511752963359375*^9}, {
  3.51175305859375*^9, 3.511753061796875*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
  "0", ",", "0", ",", "0", ",", "2", ",", "1", ",", "1", ",", "1", ",", "1", 
   ",", "2", ",", "1", ",", "1", ",", "0", ",", "0", ",", "1", ",", "0", ",", 
   "0", ",", "1", ",", "2", ",", "2", ",", "0", ",", "2", ",", "2", ",", "0", 
   ",", "2", ",", "2", ",", "0", ",", "0", ",", "2", ",", "0", ",", "2", ",", 
   "1", ",", "1", ",", "2", ",", "0", ",", "2", ",", "2", ",", "0", ",", "0", 
   ",", "0", ",", "0", ",", "0", ",", "1", ",", "0", ",", "1", ",", "2", ",", 
   "1", ",", "1", ",", "0", ",", "1", ",", "0"}], "}"}]], "Output",
 CellChangeTimes->{3.511752964578125*^9, 3.511753062484375*^9}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"sa", "=", 
  RowBox[{"SparseArray", "[", "a", "]"}], 
  RowBox[{"(*", 
   RowBox[{"use", " ", "this", " ", "when", " ", "saving"}], 
   "*)"}]}]], "Input",
 CellChangeTimes->{{3.511753238203125*^9, 3.51175325084375*^9}, {
  3.51175350321875*^9, 3.5117535104375*^9}}],

Cell[BoxData[
 TagBox[
  RowBox[{"SparseArray", "[", 
   RowBox[{
    InterpretationBox[
     RowBox[{"\<\"<\"\>", "\[InvisibleSpace]", "29", 
      "\[InvisibleSpace]", "\<\">\"\>"}],
     SequenceForm["<", 29, ">"],
     Editable->False], ",", 
    RowBox[{"{", "50", "}"}]}], "]"}],
  False,
  Editable->False]], "Output",
 CellChangeTimes->{{3.5117532393125*^9, 3.511753251578125*^9}}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"sa", ".", "sa"}]], "Input",
 CellChangeTimes->{{3.511753269078125*^9, 3.511753274015625*^9}, {
  3.511754875109375*^9, 3.511754898640625*^9}}],

Cell[BoxData["71"], "Output",
 CellChangeTimes->{{3.511753271046875*^9, 3.5117532744375*^9}, {
  3.511754876203125*^9, 3.51175489934375*^9}}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"Sort", "[", 
  RowBox[{"Normal", "[", "sa", "]"}], "]"}]], "Input",
 CellChangeTimes->{{3.511753446015625*^9, 3.511753463234375*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
  "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", 
   ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", 
   "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "1", 
   ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", 
   "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "2", ",", "2", 
   ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", 
   "2", ",", "2", ",", "2", ",", "2", ",", "2"}], "}"}]], "Output",
 CellChangeTimes->{{3.511753448859375*^9, 3.511753463796875*^9}}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"SupportVectors", "[", "a", "]"}]], "Input",
 CellChangeTimes->{{3.511752974375*^9, 3.5117529750625*^9}, {
   3.5117532541875*^9, 3.51175325596875*^9}, 3.511753527984375*^9}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
  "4", ",", "5", ",", "6", ",", "7", ",", "8", ",", "9", ",", "10", ",", "11",
    ",", "14", ",", "17", ",", "18", ",", "19", ",", "21", ",", "22", ",", 
   "24", ",", "25", ",", "28", ",", "30", ",", "31", ",", "32", ",", "33", 
   ",", "35", ",", "36", ",", "42", ",", "44", ",", "45", ",", "46", ",", 
   "47", ",", "49"}], "}"}]], "Output",
 CellChangeTimes->{
  3.51175297565625*^9, 3.511753064015625*^9, {3.5117532565625*^9, 
   3.5117532601875*^9}, {3.511753364859375*^9, 3.511753393640625*^9}, 
   3.5117535285*^9, {3.511753558703125*^9, 3.511753575609375*^9}}]
}, Open  ]]
}, Closed]]
}, Open  ]]
},
AutoGeneratedPackage->Automatic,
WindowSize->{1016, 585},
WindowMargins->{{0, Automatic}, {0, Automatic}},
Magnification->1.2000000476837158`,
FrontEndVersion->"8.0 for Microsoft Windows (32-bit) (November 7, 2010)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[579, 22, 97, 1, 99, "Title"],
Cell[679, 25, 186, 4, 39, "Input",
 InitializationCell->True],
Cell[CellGroupData[{
Cell[890, 33, 99, 1, 85, "Section"],
Cell[992, 36, 2275, 47, 229, "Input",
 InitializationCell->True],
Cell[CellGroupData[{
Cell[3292, 87, 129, 3, 43, "Subsection"],
Cell[3424, 92, 3087, 65, 445, "Input",
 InitializationCell->True]
}, Closed]],
Cell[CellGroupData[{
Cell[6548, 162, 95, 1, 32, "Subsection"],
Cell[6646, 165, 3784, 81, 364, "Input",
 InitializationCell->True],
Cell[10433, 248, 5206, 108, 364, "Input",
 InitializationCell->True]
}, Closed]],
Cell[CellGroupData[{
Cell[15676, 361, 86, 1, 32, "Subsection"],
Cell[15765, 364, 2593, 42, 148, "Input",
 InitializationCell->True]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[18407, 412, 117, 2, 85, "Section",
 InitializationCell->True],
Cell[CellGroupData[{
Cell[18549, 418, 96, 1, 43, "Subsection"],
Cell[18648, 421, 17700, 385, 2146, "Input",
 InitializationCell->True],
Cell[36351, 808, 15200, 328, 1147, "Input",
 InitializationCell->True]
}, Open  ]],
Cell[CellGroupData[{
Cell[51588, 1141, 122, 2, 43, "Subsection"],
Cell[51713, 1145, 5723, 170, 599, "Input",
 InitializationCell->True]
}, Closed]],
Cell[CellGroupData[{
Cell[57473, 1320, 156, 2, 32, "Subsection"],
Cell[57632, 1324, 19477, 438, 2428, "Input",
 InitializationCell->True]
}, Open  ]],
Cell[CellGroupData[{
Cell[77146, 1767, 99, 1, 43, "Subsection"],
Cell[77248, 1770, 4619, 112, 402, "Input",
 InitializationCell->True]
}, Closed]],
Cell[CellGroupData[{
Cell[81904, 1887, 104, 1, 32, "Subsection"],
Cell[82011, 1890, 20175, 457, 2224, "Input",
 InitializationCell->True],
Cell[102189, 2349, 222, 6, 67, "Input",
 InitializationCell->True]
}, Open  ]]
}, Open  ]],
Cell[CellGroupData[{
Cell[102460, 2361, 193, 3, 34, "Subsubtitle"],
Cell[CellGroupData[{
Cell[102678, 2368, 1530, 47, 158, "Input"],
Cell[104211, 2417, 1378, 38, 66, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[105626, 2460, 309, 7, 31, "Input"],
Cell[105938, 2469, 473, 13, 38, "Output"]
}, Open  ]],
Cell[106426, 2485, 223, 7, 39, "Input"],
Cell[CellGroupData[{
Cell[106674, 2496, 425, 11, 72, "Input"],
Cell[107102, 2509, 93, 1, 38, "Output"]
}, Open  ]],
Cell[107210, 2513, 426, 11, 67, "Input"],
Cell[CellGroupData[{
Cell[107661, 2528, 285, 7, 39, "Input"],
Cell[107949, 2537, 644, 10, 64, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[108630, 2552, 290, 7, 39, "Input"],
Cell[108923, 2561, 389, 12, 38, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[109349, 2578, 166, 3, 39, "Input"],
Cell[109518, 2583, 141, 2, 38, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[109696, 2590, 157, 3, 39, "Input"],
Cell[109856, 2595, 646, 10, 64, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[110539, 2610, 197, 3, 39, "Input"],
Cell[110739, 2615, 610, 11, 64, "Output"]
}, Open  ]]
}, Closed]]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
